Richard Smith | 9ca5c42 | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -fms-extensions %s |
Andy Gibbs | c6e68da | 2012-10-19 12:44:48 +0000 | [diff] [blame^] | 2 | // expected-no-diagnostics |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 3 | |
| 4 | #define P(e) static_assert(noexcept(e), "expected nothrow") |
| 5 | #define N(e) static_assert(!noexcept(e), "expected throw") |
Sebastian Redl | dbd14bd | 2010-09-10 20:55:50 +0000 | [diff] [blame] | 6 | #define B(b, e) static_assert(b == noexcept(e), "expectation failed") |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 7 | |
| 8 | void simple() { |
| 9 | P(0); |
| 10 | P(0 + 0); |
| 11 | int i; |
| 12 | P(i); |
| 13 | P(sizeof(0)); |
| 14 | P(static_cast<int>(0)); |
| 15 | N(throw 0); |
Sebastian Redl | 4fa4a6b | 2010-09-10 21:03:58 +0000 | [diff] [blame] | 16 | N((throw 0, 0)); |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | void nospec(); |
| 20 | void allspec() throw(...); |
| 21 | void intspec() throw(int); |
| 22 | void emptyspec() throw(); |
Sebastian Redl | b8a76c4 | 2010-09-10 22:34:40 +0000 | [diff] [blame] | 23 | void nothrowattr() __attribute__((nothrow)); |
Sebastian Redl | 52ddca2 | 2011-03-15 20:45:42 +0000 | [diff] [blame] | 24 | void noexcept_true() noexcept; |
| 25 | void noexcept_false() noexcept(false); |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 26 | |
| 27 | void call() { |
| 28 | N(nospec()); |
| 29 | N(allspec()); |
| 30 | N(intspec()); |
| 31 | P(emptyspec()); |
Sebastian Redl | b8a76c4 | 2010-09-10 22:34:40 +0000 | [diff] [blame] | 32 | P(nothrowattr()); |
Sebastian Redl | 52ddca2 | 2011-03-15 20:45:42 +0000 | [diff] [blame] | 33 | P(noexcept_true()); |
| 34 | N(noexcept_false()); |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void (*pnospec)(); |
| 38 | void (*pallspec)() throw(...); |
| 39 | void (*pintspec)() throw(int); |
| 40 | void (*pemptyspec)() throw(); |
| 41 | |
| 42 | void callptr() { |
| 43 | N(pnospec()); |
| 44 | N((*pnospec)()); |
| 45 | N(pallspec()); |
| 46 | N((*pallspec)()); |
| 47 | N(pintspec()); |
| 48 | N((*pintspec)()); |
| 49 | P(pemptyspec()); |
| 50 | P((*pemptyspec)()); |
| 51 | } |
| 52 | |
| 53 | struct S1 { |
| 54 | void nospec(); |
| 55 | void allspec() throw(...); |
| 56 | void intspec() throw(int); |
| 57 | void emptyspec() throw(); |
| 58 | }; |
| 59 | |
| 60 | void callmem() { |
| 61 | S1 s; |
| 62 | N(s.nospec()); |
| 63 | N(s.allspec()); |
| 64 | N(s.intspec()); |
| 65 | P(s.emptyspec()); |
| 66 | } |
| 67 | |
| 68 | void (S1::*mpnospec)(); |
| 69 | void (S1::*mpallspec)() throw(...); |
| 70 | void (S1::*mpintspec)() throw(int); |
| 71 | void (S1::*mpemptyspec)() throw(); |
| 72 | |
| 73 | void callmemptr() { |
| 74 | S1 s; |
| 75 | N((s.*mpnospec)()); |
| 76 | N((s.*mpallspec)()); |
| 77 | N((s.*mpintspec)()); |
| 78 | P((s.*mpemptyspec)()); |
| 79 | } |
| 80 | |
| 81 | struct S2 { |
| 82 | S2(); |
| 83 | S2(int, int) throw(); |
| 84 | void operator +(); |
| 85 | void operator -() throw(); |
| 86 | void operator +(int); |
| 87 | void operator -(int) throw(); |
| 88 | operator int(); |
| 89 | operator float() throw(); |
| 90 | }; |
| 91 | |
| 92 | void *operator new(__typeof__(sizeof(int)) sz, int) throw(); |
| 93 | |
Sebastian Redl | a8bac37 | 2010-09-10 23:27:10 +0000 | [diff] [blame] | 94 | struct Bad1 { |
| 95 | ~Bad1() throw(int); |
| 96 | }; |
| 97 | struct Bad2 { |
| 98 | void operator delete(void*) throw(int); |
| 99 | }; |
| 100 | |
Eli Friedman | 622e4fc | 2011-05-12 02:11:32 +0000 | [diff] [blame] | 101 | typedef int X; |
| 102 | |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 103 | void implicits() { |
| 104 | N(new int); |
| 105 | P(new (0) int); |
Sebastian Redl | a8bac37 | 2010-09-10 23:27:10 +0000 | [diff] [blame] | 106 | P(delete (int*)0); |
| 107 | N(delete (Bad1*)0); |
| 108 | N(delete (Bad2*)0); |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 109 | N(S2()); |
| 110 | P(S2(0, 0)); |
| 111 | S2 s; |
| 112 | N(+s); |
| 113 | P(-s); |
| 114 | N(s + 0); |
| 115 | P(s - 0); |
| 116 | N(static_cast<int>(s)); |
| 117 | P(static_cast<float>(s)); |
Sebastian Redl | a8bac37 | 2010-09-10 23:27:10 +0000 | [diff] [blame] | 118 | N(Bad1()); |
Eli Friedman | 622e4fc | 2011-05-12 02:11:32 +0000 | [diff] [blame] | 119 | P(X().~X()); |
Sebastian Redl | 5f0180d | 2010-09-10 20:55:47 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | struct V { |
| 123 | virtual ~V() throw(); |
| 124 | }; |
| 125 | struct D : V {}; |
| 126 | |
| 127 | void dyncast() { |
| 128 | V *pv = 0; |
| 129 | D *pd = 0; |
| 130 | P(dynamic_cast<V&>(*pd)); |
| 131 | P(dynamic_cast<V*>(pd)); |
| 132 | N(dynamic_cast<D&>(*pv)); |
| 133 | P(dynamic_cast<D*>(pv)); |
| 134 | } |
| 135 | |
| 136 | namespace std { |
| 137 | struct type_info {}; |
| 138 | } |
| 139 | |
| 140 | void idtype() { |
| 141 | P(typeid(V)); |
| 142 | P(typeid((V*)0)); |
| 143 | P(typeid(*(S1*)0)); |
| 144 | N(typeid(*(V*)0)); |
| 145 | } |
| 146 | |
| 147 | void uneval() { |
| 148 | P(sizeof(typeid(*(V*)0))); |
| 149 | P(typeid(typeid(*(V*)0))); |
| 150 | } |
Sebastian Redl | dbd14bd | 2010-09-10 20:55:50 +0000 | [diff] [blame] | 151 | |
| 152 | struct G1 {}; |
| 153 | struct G2 { int i; }; |
| 154 | struct G3 { S2 s; }; |
| 155 | |
| 156 | void gencon() { |
| 157 | P(G1()); |
| 158 | P(G2()); |
| 159 | N(G3()); |
| 160 | } |
| 161 | |
Eli Friedman | c6587cc | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 162 | template <class T> void f(T&&) noexcept; |
Sebastian Redl | dbd14bd | 2010-09-10 20:55:50 +0000 | [diff] [blame] | 163 | template <typename T, bool b> |
| 164 | void late() { |
| 165 | B(b, typeid(*(T*)0)); |
| 166 | B(b, T(1)); |
| 167 | B(b, static_cast<T>(S2(0, 0))); |
| 168 | B(b, S1() + T()); |
Eli Friedman | c6587cc | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 169 | P(f(T())); |
| 170 | P(new (0) T); |
| 171 | P(delete (T*)0); |
Sebastian Redl | dbd14bd | 2010-09-10 20:55:50 +0000 | [diff] [blame] | 172 | } |
| 173 | struct S3 { |
| 174 | virtual ~S3() throw(); |
| 175 | S3() throw(); |
| 176 | explicit S3(int); |
| 177 | S3(const S2&); |
| 178 | }; |
Eli Friedman | c6587cc | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 179 | template <class T> T&& f2() noexcept; |
| 180 | template <typename T> |
| 181 | void late2() { |
| 182 | P(dynamic_cast<S3&>(f2<T&>())); |
| 183 | } |
Sebastian Redl | dbd14bd | 2010-09-10 20:55:50 +0000 | [diff] [blame] | 184 | void operator +(const S1&, float) throw(); |
| 185 | void operator +(const S1&, const S3&); |
| 186 | void tlate() { |
| 187 | late<float, true>(); |
| 188 | late<S3, false>(); |
Eli Friedman | c6587cc | 2011-05-11 05:22:44 +0000 | [diff] [blame] | 189 | late2<S3>(); |
Sebastian Redl | dbd14bd | 2010-09-10 20:55:50 +0000 | [diff] [blame] | 190 | } |