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