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