2010-09-11 04:55:47 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fms-extensions %s
|
|
|
|
|
|
|
|
#define P(e) static_assert(noexcept(e), "expected nothrow")
|
|
|
|
#define N(e) static_assert(!noexcept(e), "expected throw")
|
2010-09-11 04:55:50 +08:00
|
|
|
#define B(b, e) static_assert(b == noexcept(e), "expectation failed")
|
2010-09-11 04:55:47 +08:00
|
|
|
|
|
|
|
void simple() {
|
|
|
|
P(0);
|
|
|
|
P(0 + 0);
|
|
|
|
int i;
|
|
|
|
P(i);
|
|
|
|
P(sizeof(0));
|
|
|
|
P(static_cast<int>(0));
|
|
|
|
N(throw 0);
|
2010-09-11 05:03:58 +08:00
|
|
|
N((throw 0, 0));
|
2010-09-11 04:55:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void nospec();
|
|
|
|
void allspec() throw(...);
|
|
|
|
void intspec() throw(int);
|
|
|
|
void emptyspec() throw();
|
2010-09-11 06:34:40 +08:00
|
|
|
void nothrowattr() __attribute__((nothrow));
|
2010-09-11 04:55:47 +08:00
|
|
|
|
|
|
|
void call() {
|
|
|
|
N(nospec());
|
|
|
|
N(allspec());
|
|
|
|
N(intspec());
|
|
|
|
P(emptyspec());
|
2010-09-11 06:34:40 +08:00
|
|
|
P(nothrowattr());
|
2010-09-11 04:55:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void (*pnospec)();
|
|
|
|
void (*pallspec)() throw(...);
|
|
|
|
void (*pintspec)() throw(int);
|
|
|
|
void (*pemptyspec)() throw();
|
|
|
|
|
|
|
|
void callptr() {
|
|
|
|
N(pnospec());
|
|
|
|
N((*pnospec)());
|
|
|
|
N(pallspec());
|
|
|
|
N((*pallspec)());
|
|
|
|
N(pintspec());
|
|
|
|
N((*pintspec)());
|
|
|
|
P(pemptyspec());
|
|
|
|
P((*pemptyspec)());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S1 {
|
|
|
|
void nospec();
|
|
|
|
void allspec() throw(...);
|
|
|
|
void intspec() throw(int);
|
|
|
|
void emptyspec() throw();
|
|
|
|
};
|
|
|
|
|
|
|
|
void callmem() {
|
|
|
|
S1 s;
|
|
|
|
N(s.nospec());
|
|
|
|
N(s.allspec());
|
|
|
|
N(s.intspec());
|
|
|
|
P(s.emptyspec());
|
|
|
|
}
|
|
|
|
|
|
|
|
void (S1::*mpnospec)();
|
|
|
|
void (S1::*mpallspec)() throw(...);
|
|
|
|
void (S1::*mpintspec)() throw(int);
|
|
|
|
void (S1::*mpemptyspec)() throw();
|
|
|
|
|
|
|
|
void callmemptr() {
|
|
|
|
S1 s;
|
|
|
|
N((s.*mpnospec)());
|
|
|
|
N((s.*mpallspec)());
|
|
|
|
N((s.*mpintspec)());
|
|
|
|
P((s.*mpemptyspec)());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S2 {
|
|
|
|
S2();
|
|
|
|
S2(int, int) throw();
|
|
|
|
void operator +();
|
|
|
|
void operator -() throw();
|
|
|
|
void operator +(int);
|
|
|
|
void operator -(int) throw();
|
|
|
|
operator int();
|
|
|
|
operator float() throw();
|
|
|
|
};
|
|
|
|
|
|
|
|
void *operator new(__typeof__(sizeof(int)) sz, int) throw();
|
|
|
|
|
|
|
|
void implicits() {
|
|
|
|
N(new int);
|
|
|
|
P(new (0) int);
|
|
|
|
N(S2());
|
|
|
|
P(S2(0, 0));
|
|
|
|
S2 s;
|
|
|
|
N(+s);
|
|
|
|
P(-s);
|
|
|
|
N(s + 0);
|
|
|
|
P(s - 0);
|
|
|
|
N(static_cast<int>(s));
|
|
|
|
P(static_cast<float>(s));
|
|
|
|
// FIXME: test destructors of temporaries
|
|
|
|
}
|
|
|
|
|
|
|
|
struct V {
|
|
|
|
virtual ~V() throw();
|
|
|
|
};
|
|
|
|
struct D : V {};
|
|
|
|
|
|
|
|
void dyncast() {
|
|
|
|
V *pv = 0;
|
|
|
|
D *pd = 0;
|
|
|
|
P(dynamic_cast<V&>(*pd));
|
|
|
|
P(dynamic_cast<V*>(pd));
|
|
|
|
N(dynamic_cast<D&>(*pv));
|
|
|
|
P(dynamic_cast<D*>(pv));
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
struct type_info {};
|
|
|
|
}
|
|
|
|
|
|
|
|
void idtype() {
|
|
|
|
P(typeid(V));
|
|
|
|
P(typeid((V*)0));
|
|
|
|
P(typeid(*(S1*)0));
|
|
|
|
N(typeid(*(V*)0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void uneval() {
|
|
|
|
P(sizeof(typeid(*(V*)0)));
|
|
|
|
P(typeid(typeid(*(V*)0)));
|
|
|
|
}
|
2010-09-11 04:55:50 +08:00
|
|
|
|
|
|
|
struct G1 {};
|
|
|
|
struct G2 { int i; };
|
|
|
|
struct G3 { S2 s; };
|
|
|
|
|
|
|
|
void gencon() {
|
|
|
|
P(G1());
|
|
|
|
P(G2());
|
|
|
|
N(G3());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, bool b>
|
|
|
|
void late() {
|
|
|
|
B(b, typeid(*(T*)0));
|
|
|
|
B(b, T(1));
|
|
|
|
B(b, static_cast<T>(S2(0, 0)));
|
|
|
|
B(b, S1() + T());
|
|
|
|
}
|
|
|
|
struct S3 {
|
|
|
|
virtual ~S3() throw();
|
|
|
|
S3() throw();
|
|
|
|
explicit S3(int);
|
|
|
|
S3(const S2&);
|
|
|
|
};
|
|
|
|
void operator +(const S1&, float) throw();
|
|
|
|
void operator +(const S1&, const S3&);
|
|
|
|
void tlate() {
|
|
|
|
late<float, true>();
|
|
|
|
late<S3, false>();
|
|
|
|
}
|