blob: 1f5969d49327174fc1b89bac0338ebc0fe473cb6 [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
Andy Gibbsc6e68da2012-10-19 12:44:48 +00002// expected-no-diagnostics
Sebastian Redl5f0180d2010-09-10 20:55:47 +00003
4#define P(e) static_assert(noexcept(e), "expected nothrow")
5#define N(e) static_assert(!noexcept(e), "expected throw")
Sebastian Redldbd14bd2010-09-10 20:55:50 +00006#define B(b, e) static_assert(b == noexcept(e), "expectation failed")
Sebastian Redl5f0180d2010-09-10 20:55:47 +00007
8void simple() {
9 P(0);
10 P(0 + 0);
11 int i;
12 P(i);
13 P(sizeof(0));
14 P(static_cast<int>(0));
15 N(throw 0);
Sebastian Redl4fa4a6b2010-09-10 21:03:58 +000016 N((throw 0, 0));
Sebastian Redl5f0180d2010-09-10 20:55:47 +000017}
18
19void nospec();
20void allspec() throw(...);
21void intspec() throw(int);
22void emptyspec() throw();
Sebastian Redlb8a76c42010-09-10 22:34:40 +000023void nothrowattr() __attribute__((nothrow));
Sebastian Redl52ddca22011-03-15 20:45:42 +000024void noexcept_true() noexcept;
25void noexcept_false() noexcept(false);
Sebastian Redl5f0180d2010-09-10 20:55:47 +000026
27void call() {
28 N(nospec());
29 N(allspec());
30 N(intspec());
31 P(emptyspec());
Sebastian Redlb8a76c42010-09-10 22:34:40 +000032 P(nothrowattr());
Sebastian Redl52ddca22011-03-15 20:45:42 +000033 P(noexcept_true());
34 N(noexcept_false());
Sebastian Redl5f0180d2010-09-10 20:55:47 +000035}
36
37void (*pnospec)();
38void (*pallspec)() throw(...);
39void (*pintspec)() throw(int);
40void (*pemptyspec)() throw();
41
42void callptr() {
43 N(pnospec());
44 N((*pnospec)());
45 N(pallspec());
46 N((*pallspec)());
47 N(pintspec());
48 N((*pintspec)());
49 P(pemptyspec());
50 P((*pemptyspec)());
51}
52
53struct S1 {
54 void nospec();
55 void allspec() throw(...);
56 void intspec() throw(int);
57 void emptyspec() throw();
58};
59
60void callmem() {
61 S1 s;
62 N(s.nospec());
63 N(s.allspec());
64 N(s.intspec());
65 P(s.emptyspec());
66}
67
68void (S1::*mpnospec)();
69void (S1::*mpallspec)() throw(...);
70void (S1::*mpintspec)() throw(int);
71void (S1::*mpemptyspec)() throw();
72
73void callmemptr() {
74 S1 s;
75 N((s.*mpnospec)());
76 N((s.*mpallspec)());
77 N((s.*mpintspec)());
78 P((s.*mpemptyspec)());
79}
80
81struct S2 {
82 S2();
83 S2(int, int) throw();
84 void operator +();
85 void operator -() throw();
86 void operator +(int);
87 void operator -(int) throw();
88 operator int();
89 operator float() throw();
90};
91
92void *operator new(__typeof__(sizeof(int)) sz, int) throw();
93
Sebastian Redla8bac372010-09-10 23:27:10 +000094struct Bad1 {
95 ~Bad1() throw(int);
96};
97struct Bad2 {
98 void operator delete(void*) throw(int);
99};
100
Eli Friedman622e4fc2011-05-12 02:11:32 +0000101typedef int X;
102
Sebastian Redl5f0180d2010-09-10 20:55:47 +0000103void implicits() {
104 N(new int);
105 P(new (0) int);
Sebastian Redla8bac372010-09-10 23:27:10 +0000106 P(delete (int*)0);
107 N(delete (Bad1*)0);
108 N(delete (Bad2*)0);
Sebastian Redl5f0180d2010-09-10 20:55:47 +0000109 N(S2());
110 P(S2(0, 0));
111 S2 s;
112 N(+s);
113 P(-s);
114 N(s + 0);
115 P(s - 0);
116 N(static_cast<int>(s));
117 P(static_cast<float>(s));
Sebastian Redla8bac372010-09-10 23:27:10 +0000118 N(Bad1());
Eli Friedman622e4fc2011-05-12 02:11:32 +0000119 P(X().~X());
Sebastian Redl5f0180d2010-09-10 20:55:47 +0000120}
121
122struct V {
123 virtual ~V() throw();
124};
125struct D : V {};
126
127void dyncast() {
128 V *pv = 0;
129 D *pd = 0;
130 P(dynamic_cast<V&>(*pd));
131 P(dynamic_cast<V*>(pd));
132 N(dynamic_cast<D&>(*pv));
133 P(dynamic_cast<D*>(pv));
134}
135
136namespace std {
137 struct type_info {};
138}
139
140void idtype() {
141 P(typeid(V));
142 P(typeid((V*)0));
143 P(typeid(*(S1*)0));
144 N(typeid(*(V*)0));
145}
146
147void uneval() {
148 P(sizeof(typeid(*(V*)0)));
149 P(typeid(typeid(*(V*)0)));
150}
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000151
152struct G1 {};
153struct G2 { int i; };
154struct G3 { S2 s; };
155
156void gencon() {
157 P(G1());
158 P(G2());
159 N(G3());
160}
161
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000162template <class T> void f(T&&) noexcept;
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000163template <typename T, bool b>
164void late() {
165 B(b, typeid(*(T*)0));
166 B(b, T(1));
167 B(b, static_cast<T>(S2(0, 0)));
168 B(b, S1() + T());
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000169 P(f(T()));
170 P(new (0) T);
171 P(delete (T*)0);
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000172}
173struct S3 {
174 virtual ~S3() throw();
175 S3() throw();
176 explicit S3(int);
177 S3(const S2&);
178};
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000179template <class T> T&& f2() noexcept;
180template <typename T>
181void late2() {
182 P(dynamic_cast<S3&>(f2<T&>()));
183}
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000184void operator +(const S1&, float) throw();
185void operator +(const S1&, const S3&);
186void tlate() {
187 late<float, true>();
188 late<S3, false>();
Eli Friedmanc6587cc2011-05-11 05:22:44 +0000189 late2<S3>();
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000190}