1 // RUN: %clang_cc1 %s -Wno-uninitialized -std=c++11 -fsyntax-only -verify 2 3 struct A { AA4 constexpr A() : a(b + 1), b(a + 1) {} // expected-note 5{{outside its lifetime}} 5 int a; 6 int b; 7 }; 8 struct B { // expected-note {{in call to 'A()'}} 9 A a; 10 }; 11 12 constexpr A a1; // expected-error {{constant expression}} expected-note {{in call to 'A()'}} 13 constexpr A a2 = A(); // expected-error {{constant expression}} expected-note {{in call to 'A()'}} f()14void f() { 15 constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}} 16 } 17 18 constexpr B b1; // expected-error {{constant expression}} expected-note {{in call to 'B()'}} 19 constexpr B b2 = B(); // ok 20 static_assert(b2.a.a == 1, ""); 21 static_assert(b2.a.b == 2, ""); 22 23 struct C { 24 int c; 25 }; 26 struct D : C { int d; }; 27 constexpr C c1; // expected-error {{without a user-provided default constructor}} 28 constexpr C c2 = C(); // ok 29 constexpr D d1; // expected-error {{without a user-provided default constructor}} 30 constexpr D d2 = D(); // ok with DR1452 31 static_assert(D().c == 0, ""); 32 static_assert(D().d == 0, ""); 33 34 struct V : virtual C {}; 35 template<typename T> struct Z : T { ZZ36 constexpr Z() : V() {} 37 }; 38 constexpr int n = Z<V>().c; // expected-error {{constant expression}} expected-note {{non-literal type 'Z<V>'}} 39 40 struct E { // expected-note {{in call to 'A()'}} 41 A a[2]; 42 }; 43 constexpr E e1; // expected-error {{constant expression}} expected-note {{in call to 'E()'}} 44 constexpr E e2 = E(); 45 static_assert(e2.a[0].a == 1, ""); 46 static_assert(e2.a[0].b == 2, ""); 47 static_assert(e2.a[1].a == 1, ""); 48 static_assert(e2.a[1].b == 2, ""); 49