blob: e4d1537cdc184f2c31e477738c8e5495502f002b [file] [log] [blame]
Sebastian Redl5f0180d2010-09-10 20:55:47 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fms-extensions %s
2
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();
22
23void call() {
24 N(nospec());
25 N(allspec());
26 N(intspec());
27 P(emptyspec());
28}
29
30void (*pnospec)();
31void (*pallspec)() throw(...);
32void (*pintspec)() throw(int);
33void (*pemptyspec)() throw();
34
35void callptr() {
36 N(pnospec());
37 N((*pnospec)());
38 N(pallspec());
39 N((*pallspec)());
40 N(pintspec());
41 N((*pintspec)());
42 P(pemptyspec());
43 P((*pemptyspec)());
44}
45
46struct S1 {
47 void nospec();
48 void allspec() throw(...);
49 void intspec() throw(int);
50 void emptyspec() throw();
51};
52
53void callmem() {
54 S1 s;
55 N(s.nospec());
56 N(s.allspec());
57 N(s.intspec());
58 P(s.emptyspec());
59}
60
61void (S1::*mpnospec)();
62void (S1::*mpallspec)() throw(...);
63void (S1::*mpintspec)() throw(int);
64void (S1::*mpemptyspec)() throw();
65
66void callmemptr() {
67 S1 s;
68 N((s.*mpnospec)());
69 N((s.*mpallspec)());
70 N((s.*mpintspec)());
71 P((s.*mpemptyspec)());
72}
73
74struct S2 {
75 S2();
76 S2(int, int) throw();
77 void operator +();
78 void operator -() throw();
79 void operator +(int);
80 void operator -(int) throw();
81 operator int();
82 operator float() throw();
83};
84
85void *operator new(__typeof__(sizeof(int)) sz, int) throw();
86
87void implicits() {
88 N(new int);
89 P(new (0) int);
90 N(S2());
91 P(S2(0, 0));
92 S2 s;
93 N(+s);
94 P(-s);
95 N(s + 0);
96 P(s - 0);
97 N(static_cast<int>(s));
98 P(static_cast<float>(s));
99 // FIXME: test destructors of temporaries
100}
101
102struct V {
103 virtual ~V() throw();
104};
105struct D : V {};
106
107void dyncast() {
108 V *pv = 0;
109 D *pd = 0;
110 P(dynamic_cast<V&>(*pd));
111 P(dynamic_cast<V*>(pd));
112 N(dynamic_cast<D&>(*pv));
113 P(dynamic_cast<D*>(pv));
114}
115
116namespace std {
117 struct type_info {};
118}
119
120void idtype() {
121 P(typeid(V));
122 P(typeid((V*)0));
123 P(typeid(*(S1*)0));
124 N(typeid(*(V*)0));
125}
126
127void uneval() {
128 P(sizeof(typeid(*(V*)0)));
129 P(typeid(typeid(*(V*)0)));
130}
Sebastian Redldbd14bd2010-09-10 20:55:50 +0000131
132struct G1 {};
133struct G2 { int i; };
134struct G3 { S2 s; };
135
136void gencon() {
137 P(G1());
138 P(G2());
139 N(G3());
140}
141
142template <typename T, bool b>
143void late() {
144 B(b, typeid(*(T*)0));
145 B(b, T(1));
146 B(b, static_cast<T>(S2(0, 0)));
147 B(b, S1() + T());
148}
149struct S3 {
150 virtual ~S3() throw();
151 S3() throw();
152 explicit S3(int);
153 S3(const S2&);
154};
155void operator +(const S1&, float) throw();
156void operator +(const S1&, const S3&);
157void tlate() {
158 late<float, true>();
159 late<S3, false>();
160}