106 lines · cpp
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-exceptions10// REQUIRES: c++03 || c++11 || c++1411 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 deprecated17#endif18 19struct A20{21 static int count;22 int id_;23 A() : id_(++count) {}24 ~A() {assert(id_ == count--);}25 26private:27 A(const A&);28 A& operator=(const A&);29};30 31int A::count = 0;32 33struct B34{35 static int count;36 int id_;37 B() : id_(++count) {}38 ~B() {assert(id_ == count--);}39 40private:41 B(const B&);42 B& operator=(const B&);43};44 45int B::count = 0;46 47struct C48{49 static int count;50 int id_;51 C() : id_(++count) {}52 ~C() {assert(id_ == count--);}53 54private:55 C(const C&);56 C& operator=(const C&);57};58 59int C::count = 0;60 61void f2()62{63 C c;64 A a;65 throw 55;66 B b;67}68 69void f1() throw (long, char, int, double)70{71 A a;72 B b;73 f2();74 C c;75}76 77int main(int, char**)78{79 try80 {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}106