blob: 19e8e7597e850e224b0ad3d139e088edd548ada4 [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 {
Richard Smithb9d0b762012-07-27 04:22:15 +000017 int &n = b() ? Recurse().n : k; // expected-error {{defaulted default constructor of 'Recurse' cannot be used by non-static data member initializer which appears before end of class definition}}
Richard Smith7a614d82011-06-11 17:19:42 +000018};
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}}
Richard Smith83a22ec2012-05-09 08:23:23 +000031 T<sizeof(as) / sizeof(int)> x;
David Blaikie3164c142012-02-14 09:00:46 +000032 // test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid
33 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}}
Richard Smith7a614d82011-06-11 17:19:42 +000035};
36
37struct ThrowCtor { ThrowCtor(int) noexcept(false); };
38struct NoThrowCtor { NoThrowCtor(int) noexcept(true); };
39
40struct Throw { ThrowCtor tc = 42; };
41struct NoThrow { NoThrowCtor tc = 42; };
42
43static_assert(!noexcept(Throw()), "incorrect exception specification");
44static_assert(noexcept(NoThrow()), "incorrect exception specification");
45
46struct CheckExcSpec {
47 CheckExcSpec() noexcept(true) = default;
48 int n = 0;
49};
50struct 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};
Richard Smithc2cdd532011-06-12 11:43:46 +000054
55struct TypedefInit {
56 typedef int A = 0; // expected-error {{illegal initializer}}
57};
Douglas Gregor2eef4272011-09-07 20:36:12 +000058
59// PR10578 / <rdar://problem/9877267>
60namespace PR10578 {
61 template<typename T>
62 struct X {
63 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
72 Y::Y() try { // expected-note{{in instantiation of member function 'PR10578::X<int>::X' requested here}}
73 } catch(...) {
74 }
75}
Richard Smith774d8b42013-01-08 00:08:23 +000076
77namespace PR14838 {
78 struct base { ~base() {} };
79 class function : base {
80 ~function() {} // expected-note {{implicitly declared private here}}
81 public:
82 function(...) {}
83 };
84 struct thing {};
85 struct another {
86 another() : r(thing()) {}
87 // expected-error@-1 {{temporary of type 'const PR14838::function' has private destructor}}
88 // expected-warning@-2 {{binding reference member 'r' to a temporary value}}
89 const function &r; // expected-note {{reference member declared here}}
90 } af;
91}