blob: b5de1a7f8fee07acb4be839329b75d9cdc98dc8e [file] [log] [blame]
Richard Smith9ca5c422011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -fms-extensions %s
Sebastian Redl5f0180d2010-09-10 20:55:47 +00002
3#define P(e) static_assert(noexcept(e), "expected nothrow")
4#define N(e) static_assert(!noexcept(e), "expected throw")
Sebastian Redldbd14bd2010-09-10 20:55:50 +00005#define B(b, e) static_assert(b == noexcept(e), "expectation failed")
Sebastian Redl5f0180d2010-09-10 20:55:47 +00006
7void simple() {
8 P(0);
9 P(0 + 0);
10 int i;
11 P(i);
12 P(sizeof(0));
13 P(static_cast<int>(0));
14 N(throw 0);
Sebastian Redl4fa4a6b2010-09-10 21:03:58 +000015 N((throw 0, 0));
Sebastian Redl5f0180d2010-09-10 20:55:47 +000016}
17
18void nospec();
19void allspec() throw(...);
20void intspec() throw(int);
21void emptyspec() throw();
Sebastian Redlb8a76c42010-09-10 22:34:40 +000022void nothrowattr() __attribute__((nothrow));
Sebastian Redl52ddca22011-03-15 20:45:42 +000023void noexcept_true() noexcept;
24void noexcept_false() noexcept(false);
Sebastian Redl5f0180d2010-09-10 20:55:47 +000025
26void call() {
27 N(nospec());
28 N(allspec());
29 N(intspec());
30 P(emptyspec());
Sebastian Redlb8a76c42010-09-10 22:34:40 +000031 P(nothrowattr());
Sebastian Redl52ddca22011-03-15 20:45:42 +000032 P(noexcept_true());
33 N(noexcept_false());
Sebastian Redl5f0180d2010-09-10 20:55:47 +000034}
35
36void (*pnospec)();
37void (*pallspec)() throw(...);
38void (*pintspec)() throw(int);
39void (*pemptyspec)() throw();
40
41void callptr() {
42 N(pnospec());
43 N((*pnospec)());
44 N(pallspec());
45 N((*pallspec)());
46 N(pintspec());
47 N((*pintspec)());
48 P(pemptyspec());
49 P((*pemptyspec)());
50}
51
52struct S1 {
53 void nospec();
54 void allspec() throw(...);
55 void intspec() throw(int);
56 void emptyspec() throw();
57};
58
59void callmem() {
60 S1 s;
61 N(s.nospec());
62 N(s.allspec());
63 N(s.intspec());
64 P(s.emptyspec());
65}
66
67void (S1::*mpnospec)();
68void (S1::*mpallspec)() throw(...);
69void (S1::*mpintspec)() throw(int);
70void (S1::*mpemptyspec)() throw();
71
72void callmemptr() {
73 S1 s;
74 N((s.*mpnospec)());
75 N((s.*mpallspec)());
76 N((s.*mpintspec)());
77 P((s.*mpemptyspec)());
78}
79
80struct S2 {
81 S2();
82 S2(int, int) throw();
83 void operator +();
84 void operator -() throw();
85 void operator +(int);
86 void operator -(int) throw();
87 operator int();
88 operator float() throw();
89};
90
91void *operator new(__typeof__(sizeof(int)) sz, int) throw();
92
Sebastian Redla8bac372010-09-10 23:27:10 +000093struct Bad1 {
94 ~Bad1() throw(int);
95};
96struct Bad2 {
97 void operator delete(void*) throw(int);
98};
99
Eli Friedman622e4fc2011-05-12 02:11:32 +0000100typedef int X;
101
Sebastian Redl5f0180d2010-09-10 20:55:47 +0000102void implicits() {
103 N(new int);
104 P(new (0) int);
Sebastian Redla8bac372010-09-10 23:27:10 +0000105 P(delete (int*)0);
106 N(delete (Bad1*)0);
107 N(delete (Bad2*)0);
Sebastian Redl5f0180d2010-09-10 20:55:47 +0000108 N(S2());
109 P(S2(0, 0));
110 S2 s;
111 N(+s);
112 P(-s);
113 N(s + 0);
114 P(s - 0);
115 N(static_cast<int>(s));
116 P(static_cast<float>(s));
Sebastian Redla8bac372010-09-10 23:27:10 +0000117 N(Bad1());
Eli Friedman622e4fc2011-05-12 02:11:32 +0000118 P(X().~X());
Sebastian Redl5f0180d2010-09-10 20:55:47 +0000119}
120
121struct V {
122 virtual ~V() throw();
123};
124struct D : V {};
125
126void dyncast() {
127 V *pv = 0;
128 D *pd = 0;
129 P(dynamic_cast<V&>(*pd));
130 P(dynamic_cast<V*>(pd));
131 N(dynamic_cast<D&>(*pv));
132 P(dynamic_cast<D*>(pv));
133}
134
135namespace std {
136 struct type_info {};
137}
138
139void idtype() {
140 P(typeid(V));
141 P(typeid((V*)0));
142 P(typeid(*(S1*)0));
143 N(typeid(*(V*)0));
144}
145
146void uneval() {
147 P(sizeof(typeid(*(V*)0)));
148 P(typeid(typeid(*(V*)0)));
149}
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000150
151struct G1 {};
152struct G2 { int i; };
153struct G3 { S2 s; };
154
155void gencon() {
156 P(G1());
157 P(G2());
158 N(G3());
159}
160
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000161template <class T> void f(T&&) noexcept;
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000162template <typename T, bool b>
163void late() {
164 B(b, typeid(*(T*)0));
165 B(b, T(1));
166 B(b, static_cast<T>(S2(0, 0)));
167 B(b, S1() + T());
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000168 P(f(T()));
169 P(new (0) T);
170 P(delete (T*)0);
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000171}
172struct S3 {
173 virtual ~S3() throw();
174 S3() throw();
175 explicit S3(int);
176 S3(const S2&);
177};
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000178template <class T> T&& f2() noexcept;
179template <typename T>
180void late2() {
181 P(dynamic_cast<S3&>(f2<T&>()));
182}
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000183void operator +(const S1&, float) throw();
184void operator +(const S1&, const S3&);
185void tlate() {
186 late<float, true>();
187 late<S3, false>();
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000188 late2<S3>();
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000189}