Richard Smith | 5120188 | 2011-12-30 21:15:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify |
| 2 | |
| 3 | struct A { |
| 4 | constexpr A() : a(b + 1), b(a + 1) {} // expected-note {{uninitialized}} |
| 5 | int a; |
| 6 | int b; |
| 7 | }; |
| 8 | struct B { |
| 9 | A a; |
| 10 | }; |
| 11 | |
| 12 | constexpr A a; // ok, zero initialization preceeds static initialization |
| 13 | void f() { |
| 14 | constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}} |
| 15 | } |
| 16 | |
| 17 | constexpr B b1; // expected-error {{requires a user-provided default constructor}} |
| 18 | constexpr B b2 = B(); // ok |
| 19 | static_assert(b2.a.a == 1, ""); |
| 20 | static_assert(b2.a.b == 2, ""); |
| 21 | |
| 22 | struct C { |
| 23 | int c; |
| 24 | }; |
| 25 | struct D : C { int d; }; |
| 26 | constexpr C c1; // expected-error {{requires a user-provided default constructor}} |
| 27 | constexpr C c2 = C(); // ok |
| 28 | constexpr D d1; // expected-error {{requires a user-provided default constructor}} |
| 29 | constexpr D d2 = D(); // expected-error {{constant expression}} expected-note {{non-literal type 'const D'}} |
| 30 | static_assert(D().c == 0, ""); |
| 31 | static_assert(D().d == 0, ""); |