1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s 2 3 struct Bitfield { 4 int n : 3 = 7; // expected-error {{bitfield member cannot have an in-class initializer}} 5 }; 6 7 int a; 8 class NoWarning { 9 int &n = a; 10 public: GetN()11 int &GetN() { return n; } 12 }; 13 14 bool b(); 15 int k; 16 struct Recurse { 17 int &n = b() ? Recurse().n : k; // ok 18 }; 19 20 struct 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 26 template<int n> struct T { static const int B; }; 27 template<> struct T<2> { template<int C, int D> using B = int; }; 28 const int C = 0, D = 0; 29 struct 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 // test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid operator int[]S33 operator int[](){}; // expected-error {{'operator int' cannot be the name of a variable or data member}} \ 34 // expected-error {{array bound cannot be deduced from an in-class initializer}} 35 }; 36 37 struct ThrowCtor { ThrowCtor(int) noexcept(false); }; 38 struct NoThrowCtor { NoThrowCtor(int) noexcept(true); }; 39 40 struct Throw { ThrowCtor tc = 42; }; 41 struct NoThrow { NoThrowCtor tc = 42; }; 42 43 static_assert(!noexcept(Throw()), "incorrect exception specification"); 44 static_assert(noexcept(NoThrow()), "incorrect exception specification"); 45 46 struct CheckExcSpec { 47 CheckExcSpec() noexcept(true) = default; 48 int n = 0; 49 }; 50 struct CheckExcSpecFail { 51 CheckExcSpecFail() noexcept(true) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}} 52 ThrowCtor tc = 123; 53 }; 54 55 struct TypedefInit { 56 typedef int A = 0; // expected-error {{illegal initializer}} 57 }; 58 59 // PR10578 / <rdar://problem/9877267> 60 namespace PR10578 { 61 template<typename T> 62 struct X { XPR10578::X63 X() { 64 T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} 65 } 66 }; 67 68 struct Y : X<int> { 69 Y(); 70 }; 71 Y()72 Y::Y() try { // expected-note{{in instantiation of member function 'PR10578::X<int>::X' requested here}} 73 } catch(...) { 74 } 75 } 76