/ test / unwind_02.pass.cpp
unwind_02.pass.cpp
  1  //===------------------------- unwind_02.cpp ------------------------------===//
  2  //
  3  // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4  // See https://llvm.org/LICENSE.txt for license information.
  5  // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6  //
  7  //===----------------------------------------------------------------------===//
  8  
  9  // UNSUPPORTED: no-exceptions
 10  // REQUIRES: c++03 || c++11 || c++14
 11  
 12  #include <assert.h>
 13  
 14  #if defined(__GNUC__)
 15  #pragma GCC diagnostic ignored "-Wunreachable-code"
 16  #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated
 17  #endif
 18  
 19  struct A
 20  {
 21      static int count;
 22      int id_;
 23      A() : id_(++count) {}
 24      ~A() {assert(id_ == count--);}
 25  
 26  private:
 27      A(const A&);
 28      A& operator=(const A&);
 29  };
 30  
 31  int A::count = 0;
 32  
 33  struct B
 34  {
 35      static int count;
 36      int id_;
 37      B() : id_(++count) {}
 38      ~B() {assert(id_ == count--);}
 39  
 40  private:
 41      B(const B&);
 42      B& operator=(const B&);
 43  };
 44  
 45  int B::count = 0;
 46  
 47  struct C
 48  {
 49      static int count;
 50      int id_;
 51      C() : id_(++count) {}
 52      ~C() {assert(id_ == count--);}
 53  
 54  private:
 55      C(const C&);
 56      C& operator=(const C&);
 57  };
 58  
 59  int C::count = 0;
 60  
 61  void f2()
 62  {
 63      C c;
 64      A a;
 65      throw 55;
 66      B b;
 67  }
 68  
 69  void f1() throw (long, char, int, double)
 70  {
 71      A a;
 72      B b;
 73      f2();
 74      C c;
 75  }
 76  
 77  int main(int, char**)
 78  {
 79      try
 80      {
 81          f1();
 82          assert(false);
 83      }
 84      catch (int* i)
 85      {
 86          assert(false);
 87      }
 88      catch (long i)
 89      {
 90          assert(false);
 91      }
 92      catch (int i)
 93      {
 94          assert(i == 55);
 95      }
 96      catch (...)
 97      {
 98          assert(false);
 99      }
100      assert(A::count == 0);
101      assert(B::count == 0);
102      assert(C::count == 0);
103  
104      return 0;
105  }