blob: c1865fc4ff32075e636fc748045c590b76bfbecb [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")
5
6void simple() {
7 P(0);
8 P(0 + 0);
9 int i;
10 P(i);
11 P(sizeof(0));
12 P(static_cast<int>(0));
13 N(throw 0);
14}
15
16void nospec();
17void allspec() throw(...);
18void intspec() throw(int);
19void emptyspec() throw();
20
21void call() {
22 N(nospec());
23 N(allspec());
24 N(intspec());
25 P(emptyspec());
26}
27
28void (*pnospec)();
29void (*pallspec)() throw(...);
30void (*pintspec)() throw(int);
31void (*pemptyspec)() throw();
32
33void callptr() {
34 N(pnospec());
35 N((*pnospec)());
36 N(pallspec());
37 N((*pallspec)());
38 N(pintspec());
39 N((*pintspec)());
40 P(pemptyspec());
41 P((*pemptyspec)());
42}
43
44struct S1 {
45 void nospec();
46 void allspec() throw(...);
47 void intspec() throw(int);
48 void emptyspec() throw();
49};
50
51void callmem() {
52 S1 s;
53 N(s.nospec());
54 N(s.allspec());
55 N(s.intspec());
56 P(s.emptyspec());
57}
58
59void (S1::*mpnospec)();
60void (S1::*mpallspec)() throw(...);
61void (S1::*mpintspec)() throw(int);
62void (S1::*mpemptyspec)() throw();
63
64void callmemptr() {
65 S1 s;
66 N((s.*mpnospec)());
67 N((s.*mpallspec)());
68 N((s.*mpintspec)());
69 P((s.*mpemptyspec)());
70}
71
72struct S2 {
73 S2();
74 S2(int, int) throw();
75 void operator +();
76 void operator -() throw();
77 void operator +(int);
78 void operator -(int) throw();
79 operator int();
80 operator float() throw();
81};
82
83void *operator new(__typeof__(sizeof(int)) sz, int) throw();
84
85void implicits() {
86 N(new int);
87 P(new (0) int);
88 N(S2());
89 P(S2(0, 0));
90 S2 s;
91 N(+s);
92 P(-s);
93 N(s + 0);
94 P(s - 0);
95 N(static_cast<int>(s));
96 P(static_cast<float>(s));
97 // FIXME: test destructors of temporaries
98}
99
100struct V {
101 virtual ~V() throw();
102};
103struct D : V {};
104
105void dyncast() {
106 V *pv = 0;
107 D *pd = 0;
108 P(dynamic_cast<V&>(*pd));
109 P(dynamic_cast<V*>(pd));
110 N(dynamic_cast<D&>(*pv));
111 P(dynamic_cast<D*>(pv));
112}
113
114namespace std {
115 struct type_info {};
116}
117
118void idtype() {
119 P(typeid(V));
120 P(typeid((V*)0));
121 P(typeid(*(S1*)0));
122 N(typeid(*(V*)0));
123}
124
125void uneval() {
126 P(sizeof(typeid(*(V*)0)));
127 P(typeid(typeid(*(V*)0)));
128}