1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -fms-extensions %s
2 // expected-no-diagnostics
3
4 #define P(e) static_assert(noexcept(e), "expected nothrow")
5 #define N(e) static_assert(!noexcept(e), "expected throw")
6 #define B(b, e) static_assert(b == noexcept(e), "expectation failed")
7
simple()8 void 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);
16 N((throw 0, 0));
17 }
18
19 void nospec();
20 void allspec() throw(...);
21 void intspec() throw(int);
22 void emptyspec() throw();
23 void nothrowattr() __attribute__((nothrow));
24 void noexcept_true() noexcept;
25 void noexcept_false() noexcept(false);
26
call()27 void call() {
28 N(nospec());
29 N(allspec());
30 N(intspec());
31 P(emptyspec());
32 P(nothrowattr());
33 P(noexcept_true());
34 N(noexcept_false());
35 }
36
37 void (*pnospec)();
38 void (*pallspec)() throw(...);
39 void (*pintspec)() throw(int);
40 void (*pemptyspec)() throw();
41
callptr()42 void 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
53 struct S1 {
54 void nospec();
55 void allspec() throw(...);
56 void intspec() throw(int);
57 void emptyspec() throw();
58 };
59
callmem()60 void callmem() {
61 S1 s;
62 N(s.nospec());
63 N(s.allspec());
64 N(s.intspec());
65 P(s.emptyspec());
66 }
67
68 void (S1::*mpnospec)();
69 void (S1::*mpallspec)() throw(...);
70 void (S1::*mpintspec)() throw(int);
71 void (S1::*mpemptyspec)() throw();
72
callmemptr()73 void callmemptr() {
74 S1 s;
75 N((s.*mpnospec)());
76 N((s.*mpallspec)());
77 N((s.*mpintspec)());
78 P((s.*mpemptyspec)());
79 }
80
81 struct 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
92 void *operator new(__typeof__(sizeof(int)) sz, int) throw();
93
94 struct Bad1 {
95 ~Bad1() throw(int);
96 };
97 struct Bad2 {
98 void operator delete(void*) throw(int);
99 };
100
101 typedef int X;
102
implicits()103 void implicits() {
104 N(new int);
105 P(new (0) int);
106 P(delete (int*)0);
107 N(delete (Bad1*)0);
108 N(delete (Bad2*)0);
109 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));
118 N(Bad1());
119 P(X().~X());
120 }
121
122 struct V {
123 virtual ~V() throw();
124 };
125 struct D : V {};
126
dyncast()127 void 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
136 namespace std {
137 struct type_info {};
138 }
139
idtype()140 void idtype() {
141 P(typeid(V));
142 P(typeid((V*)0));
143 P(typeid(*(S1*)0));
144 N(typeid(*(V*)0));
145 }
146
uneval()147 void uneval() {
148 P(sizeof(typeid(*(V*)0)));
149 P(typeid(typeid(*(V*)0)));
150 }
151
152 struct G1 {};
153 struct G2 { int i; };
154 struct G3 { S2 s; };
155
gencon()156 void gencon() {
157 P(G1());
158 P(G2());
159 N(G3());
160 }
161
162 template <class T> void f(T&&) noexcept;
163 template <typename T, bool b>
late()164 void 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());
169 P(f(T()));
170 P(new (0) T);
171 P(delete (T*)0);
172 }
173 struct S3 {
174 virtual ~S3() throw();
175 S3() throw();
176 explicit S3(int);
177 S3(const S2&);
178 };
179 template <class T> T&& f2() noexcept;
180 template <typename T>
late2()181 void late2() {
182 P(dynamic_cast<S3&>(f2<T&>()));
183 }
184 void operator +(const S1&, float) throw();
185 void operator +(const S1&, const S3&);
tlate()186 void tlate() {
187 late<float, true>();
188 late<S3, false>();
189 late2<S3>();
190 }
191