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