blob: 819c8d13db8972c8af01a30625e4a82892b59216 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s
Richard Smith7a614d82011-06-11 17:19:42 +00002
3struct Bitfield {
4 int n : 3 = 7; // expected-error {{bitfield member cannot have an in-class initializer}}
5};
6
7int a;
8class NoWarning {
9 int &n = a;
10public:
11 int &GetN() { return n; }
12};
13
14bool b();
15int k;
16struct Recurse {
17 int &n = b() ? Recurse().n : k; // ok
18};
19
20struct UnknownBound {
21 int as[] = { 1, 2, 3 }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
22 int bs[4] = { 4, 5, 6, 7 };
23 int cs[] = { 8, 9, 10 }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
24};
25
26template<int n> struct T { static const int B; };
27template<> struct T<2> { template<int C, int D> using B = int; };
28const int C = 0, D = 0;
29struct S {
30 int as[] = { decltype(x)::B<C, D>(0) }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
31 T<sizeof(as) / sizeof(int)> x; // expected-error {{requires a type specifier}}
32};
33
34struct ThrowCtor { ThrowCtor(int) noexcept(false); };
35struct NoThrowCtor { NoThrowCtor(int) noexcept(true); };
36
37struct Throw { ThrowCtor tc = 42; };
38struct NoThrow { NoThrowCtor tc = 42; };
39
40static_assert(!noexcept(Throw()), "incorrect exception specification");
41static_assert(noexcept(NoThrow()), "incorrect exception specification");
42
43struct CheckExcSpec {
44 CheckExcSpec() noexcept(true) = default;
45 int n = 0;
46};
47struct CheckExcSpecFail {
48 CheckExcSpecFail() noexcept(true) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}}
49 ThrowCtor tc = 123;
50};
Richard Smithc2cdd532011-06-12 11:43:46 +000051
52struct TypedefInit {
53 typedef int A = 0; // expected-error {{illegal initializer}}
54};
Douglas Gregor2eef4272011-09-07 20:36:12 +000055
56// PR10578 / <rdar://problem/9877267>
57namespace PR10578 {
58 template<typename T>
59 struct X {
60 X() {
61 T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
62 }
63 };
64
65 struct Y : X<int> {
66 Y();
67 };
68
69 Y::Y() try { // expected-note{{in instantiation of member function 'PR10578::X<int>::X' requested here}}
70 } catch(...) {
71 }
72}