sema.cpp revision c574959e7bb9b0fae6fcf07deb6f2ba3f15ec3b1
174343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fms-extensions %s 274343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org 374343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org#define P(e) static_assert(noexcept(e), "expected nothrow") 474343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org#define N(e) static_assert(!noexcept(e), "expected throw") 574343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org#define B(b, e) static_assert(b == noexcept(e), "expectation failed") 674343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org 774343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.orgvoid simple() { 874343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org P(0); 974343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org P(0 + 0); 1074343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org int i; 1174343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org P(i); 1274343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org P(sizeof(0)); 1374343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org P(static_cast<int>(0)); 1474343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org N(throw 0); 1574343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org N((throw 0, 0)); 1674343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org} 1774343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.org 1874343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.orgvoid nospec(); 1974343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.orgvoid allspec() throw(...); 2074343ba7bd420519a9a4f7b22977d7771286f6f8ksakamoto@chromium.orgvoid intspec() throw(int); 21void emptyspec() throw(); 22 23void call() { 24 N(nospec()); 25 N(allspec()); 26 N(intspec()); 27 P(emptyspec()); 28} 29 30void (*pnospec)(); 31void (*pallspec)() throw(...); 32void (*pintspec)() throw(int); 33void (*pemptyspec)() throw(); 34 35void 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 46struct S1 { 47 void nospec(); 48 void allspec() throw(...); 49 void intspec() throw(int); 50 void emptyspec() throw(); 51}; 52 53void callmem() { 54 S1 s; 55 N(s.nospec()); 56 N(s.allspec()); 57 N(s.intspec()); 58 P(s.emptyspec()); 59} 60 61void (S1::*mpnospec)(); 62void (S1::*mpallspec)() throw(...); 63void (S1::*mpintspec)() throw(int); 64void (S1::*mpemptyspec)() throw(); 65 66void callmemptr() { 67 S1 s; 68 N((s.*mpnospec)()); 69 N((s.*mpallspec)()); 70 N((s.*mpintspec)()); 71 P((s.*mpemptyspec)()); 72} 73 74struct 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 85void *operator new(__typeof__(sizeof(int)) sz, int) throw(); 86 87void 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 102struct V { 103 virtual ~V() throw(); 104}; 105struct D : V {}; 106 107void 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 116namespace std { 117 struct type_info {}; 118} 119 120void idtype() { 121 P(typeid(V)); 122 P(typeid((V*)0)); 123 P(typeid(*(S1*)0)); 124 N(typeid(*(V*)0)); 125} 126 127void uneval() { 128 P(sizeof(typeid(*(V*)0))); 129 P(typeid(typeid(*(V*)0))); 130} 131 132struct G1 {}; 133struct G2 { int i; }; 134struct G3 { S2 s; }; 135 136void gencon() { 137 P(G1()); 138 P(G2()); 139 N(G3()); 140} 141 142template <typename T, bool b> 143void 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} 149struct S3 { 150 virtual ~S3() throw(); 151 S3() throw(); 152 explicit S3(int); 153 S3(const S2&); 154}; 155void operator +(const S1&, float) throw(); 156void operator +(const S1&, const S3&); 157void tlate() { 158 late<float, true>(); 159 late<S3, false>(); 160} 161