llvm-project
111 строк · 1.7 Кб
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: no-exceptions
10// REQUIRES: c++03 || c++11 || c++14
11
12#include <exception>13#include <stdlib.h>14#include <assert.h>15
16#if defined(__GNUC__)17#pragma GCC diagnostic ignored "-Wunreachable-code"18#pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated19#endif20
21struct A22{
23static int count;24int id_;25A() : id_(++count) {}26~A() {assert(id_ == count--);}27
28private:29A(const A&);30A& operator=(const A&);31};32
33int A::count = 0;34
35struct B36{
37static int count;38int id_;39B() : id_(++count) {}40~B() {assert(id_ == count--);}41
42private:43B(const B&);44B& operator=(const B&);45};46
47int B::count = 0;48
49struct C50{
51static int count;52int id_;53C() : id_(++count) {}54~C() {assert(id_ == count--);}55
56private:57C(const C&);58C& operator=(const C&);59};60
61int C::count = 0;62
63void f2()64{
65C c;66A a;67throw 55;68B b;69}
70
71void f1() throw (long, char, double)72{
73A a;74B b;75f2();76C c;77}
78
79void u_handler()80{
81exit(0);82}
83
84int main(int, char**)85{
86std::set_unexpected(u_handler);87try88{89f1();90assert(false);91}92catch (int* i)93{94assert(false);95}96catch (long i)97{98assert(false);99}100catch (int i)101{102assert(i == 55);103}104catch (...)105{106assert(false);107}108assert(false);109
110return 0;111}
112