sema.cpp revision e41721e7dfabcc15cb50be9075a4153f1ad648ea
1// RUN: %clang_cc1 -fexceptions -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 N((throw 0, 0)); 16} 17 18void nospec(); 19void allspec() throw(...); 20void intspec() throw(int); 21void emptyspec() throw(); 22void nothrowattr() __attribute__((nothrow)); 23 24void call() { 25 N(nospec()); 26 N(allspec()); 27 N(intspec()); 28 P(emptyspec()); 29 P(nothrowattr()); 30} 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 89struct Bad1 { 90 ~Bad1() throw(int); 91}; 92struct Bad2 { 93 void operator delete(void*) throw(int); 94}; 95 96void implicits() { 97 N(new int); 98 P(new (0) int); 99 P(delete (int*)0); 100 N(delete (Bad1*)0); 101 N(delete (Bad2*)0); 102 N(S2()); 103 P(S2(0, 0)); 104 S2 s; 105 N(+s); 106 P(-s); 107 N(s + 0); 108 P(s - 0); 109 N(static_cast<int>(s)); 110 P(static_cast<float>(s)); 111 N(Bad1()); 112} 113 114struct V { 115 virtual ~V() throw(); 116}; 117struct D : V {}; 118 119void dyncast() { 120 V *pv = 0; 121 D *pd = 0; 122 P(dynamic_cast<V&>(*pd)); 123 P(dynamic_cast<V*>(pd)); 124 N(dynamic_cast<D&>(*pv)); 125 P(dynamic_cast<D*>(pv)); 126} 127 128namespace std { 129 struct type_info {}; 130} 131 132void idtype() { 133 P(typeid(V)); 134 P(typeid((V*)0)); 135 P(typeid(*(S1*)0)); 136 N(typeid(*(V*)0)); 137} 138 139void uneval() { 140 P(sizeof(typeid(*(V*)0))); 141 P(typeid(typeid(*(V*)0))); 142} 143 144struct G1 {}; 145struct G2 { int i; }; 146struct G3 { S2 s; }; 147 148void gencon() { 149 P(G1()); 150 P(G2()); 151 N(G3()); 152} 153 154template <typename T, bool b> 155void late() { 156 B(b, typeid(*(T*)0)); 157 B(b, T(1)); 158 B(b, static_cast<T>(S2(0, 0))); 159 B(b, S1() + T()); 160} 161struct S3 { 162 virtual ~S3() throw(); 163 S3() throw(); 164 explicit S3(int); 165 S3(const S2&); 166}; 167void operator +(const S1&, float) throw(); 168void operator +(const S1&, const S3&); 169void tlate() { 170 late<float, true>(); 171 late<S3, false>(); 172} 173