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