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 7 void 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 17 void nospec(); 18 void allspec() throw(...); 19 void intspec() throw(int); 20 void emptyspec() throw(); 21 22 void call() { 23 N(nospec()); 24 N(allspec()); 25 N(intspec()); 26 P(emptyspec()); 27 } 28 29 void (*pnospec)(); 30 void (*pallspec)() throw(...); 31 void (*pintspec)() throw(int); 32 void (*pemptyspec)() throw(); 33 34 void 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 45 struct S1 { 46 void nospec(); 47 void allspec() throw(...); 48 void intspec() throw(int); 49 void emptyspec() throw(); 50 }; 51 52 void callmem() { 53 S1 s; 54 N(s.nospec()); 55 N(s.allspec()); 56 N(s.intspec()); 57 P(s.emptyspec()); 58 } 59 60 void (S1::*mpnospec)(); 61 void (S1::*mpallspec)() throw(...); 62 void (S1::*mpintspec)() throw(int); 63 void (S1::*mpemptyspec)() throw(); 64 65 void callmemptr() { 66 S1 s; 67 N((s.*mpnospec)()); 68 N((s.*mpallspec)()); 69 N((s.*mpintspec)()); 70 P((s.*mpemptyspec)()); 71 } 72 73 struct 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 84 void *operator new(__typeof__(sizeof(int)) sz, int) throw(); 85 86 void 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 101 struct V { 102 virtual ~V() throw(); 103 }; 104 struct D : V {}; 105 106 void 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 115 namespace std { 116 struct type_info {}; 117 } 118 119 void idtype() { 120 P(typeid(V)); 121 P(typeid((V*)0)); 122 P(typeid(*(S1*)0)); 123 N(typeid(*(V*)0)); 124 } 125 126 void uneval() { 127 P(sizeof(typeid(*(V*)0))); 128 P(typeid(typeid(*(V*)0))); 129 } 130 131 struct G1 {}; 132 struct G2 { int i; }; 133 struct G3 { S2 s; }; 134 135 void gencon() { 136 P(G1()); 137 P(G2()); 138 N(G3()); 139 } 140 141 template <typename T, bool b> 142 void 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 } 148 struct S3 { 149 virtual ~S3() throw(); 150 S3() throw(); 151 explicit S3(int); 152 S3(const S2&); 153 }; 154 void operator +(const S1&, float) throw(); 155 void operator +(const S1&, const S3&); 156 void tlate() { 157 late<float, true>(); 158 late<S3, false>(); 159 } 160