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") |
| 5 | |
| 6 | void simple() { |
| 7 | P(0); |
| 8 | P(0 + 0); |
| 9 | int i; |
| 10 | P(i); |
| 11 | P(sizeof(0)); |
| 12 | P(static_cast<int>(0)); |
| 13 | N(throw 0); |
| 14 | } |
| 15 | |
| 16 | void nospec(); |
| 17 | void allspec() throw(...); |
| 18 | void intspec() throw(int); |
| 19 | void emptyspec() throw(); |
| 20 | |
| 21 | void call() { |
| 22 | N(nospec()); |
| 23 | N(allspec()); |
| 24 | N(intspec()); |
| 25 | P(emptyspec()); |
| 26 | } |
| 27 | |
| 28 | void (*pnospec)(); |
| 29 | void (*pallspec)() throw(...); |
| 30 | void (*pintspec)() throw(int); |
| 31 | void (*pemptyspec)() throw(); |
| 32 | |
| 33 | void callptr() { |
| 34 | N(pnospec()); |
| 35 | N((*pnospec)()); |
| 36 | N(pallspec()); |
| 37 | N((*pallspec)()); |
| 38 | N(pintspec()); |
| 39 | N((*pintspec)()); |
| 40 | P(pemptyspec()); |
| 41 | P((*pemptyspec)()); |
| 42 | } |
| 43 | |
| 44 | struct S1 { |
| 45 | void nospec(); |
| 46 | void allspec() throw(...); |
| 47 | void intspec() throw(int); |
| 48 | void emptyspec() throw(); |
| 49 | }; |
| 50 | |
| 51 | void callmem() { |
| 52 | S1 s; |
| 53 | N(s.nospec()); |
| 54 | N(s.allspec()); |
| 55 | N(s.intspec()); |
| 56 | P(s.emptyspec()); |
| 57 | } |
| 58 | |
| 59 | void (S1::*mpnospec)(); |
| 60 | void (S1::*mpallspec)() throw(...); |
| 61 | void (S1::*mpintspec)() throw(int); |
| 62 | void (S1::*mpemptyspec)() throw(); |
| 63 | |
| 64 | void callmemptr() { |
| 65 | S1 s; |
| 66 | N((s.*mpnospec)()); |
| 67 | N((s.*mpallspec)()); |
| 68 | N((s.*mpintspec)()); |
| 69 | P((s.*mpemptyspec)()); |
| 70 | } |
| 71 | |
| 72 | struct S2 { |
| 73 | S2(); |
| 74 | S2(int, int) throw(); |
| 75 | void operator +(); |
| 76 | void operator -() throw(); |
| 77 | void operator +(int); |
| 78 | void operator -(int) throw(); |
| 79 | operator int(); |
| 80 | operator float() throw(); |
| 81 | }; |
| 82 | |
| 83 | void *operator new(__typeof__(sizeof(int)) sz, int) throw(); |
| 84 | |
| 85 | void implicits() { |
| 86 | N(new int); |
| 87 | P(new (0) int); |
| 88 | N(S2()); |
| 89 | P(S2(0, 0)); |
| 90 | S2 s; |
| 91 | N(+s); |
| 92 | P(-s); |
| 93 | N(s + 0); |
| 94 | P(s - 0); |
| 95 | N(static_cast<int>(s)); |
| 96 | P(static_cast<float>(s)); |
| 97 | // FIXME: test destructors of temporaries |
| 98 | } |
| 99 | |
| 100 | struct V { |
| 101 | virtual ~V() throw(); |
| 102 | }; |
| 103 | struct D : V {}; |
| 104 | |
| 105 | void dyncast() { |
| 106 | V *pv = 0; |
| 107 | D *pd = 0; |
| 108 | P(dynamic_cast<V&>(*pd)); |
| 109 | P(dynamic_cast<V*>(pd)); |
| 110 | N(dynamic_cast<D&>(*pv)); |
| 111 | P(dynamic_cast<D*>(pv)); |
| 112 | } |
| 113 | |
| 114 | namespace std { |
| 115 | struct type_info {}; |
| 116 | } |
| 117 | |
| 118 | void idtype() { |
| 119 | P(typeid(V)); |
| 120 | P(typeid((V*)0)); |
| 121 | P(typeid(*(S1*)0)); |
| 122 | N(typeid(*(V*)0)); |
| 123 | } |
| 124 | |
| 125 | void uneval() { |
| 126 | P(sizeof(typeid(*(V*)0))); |
| 127 | P(typeid(typeid(*(V*)0))); |
| 128 | } |