1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -Wno-uninitialized -std=c++11 -fsyntax-only -verify 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc struct A { 4*f4a2713aSLionel Sambuc constexpr A() : a(b + 1), b(a + 1) {} // expected-note {{outside its lifetime}} 5*f4a2713aSLionel Sambuc int a; 6*f4a2713aSLionel Sambuc int b; 7*f4a2713aSLionel Sambuc }; 8*f4a2713aSLionel Sambuc struct B { 9*f4a2713aSLionel Sambuc A a; 10*f4a2713aSLionel Sambuc }; 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambuc constexpr A a; // ok, zero initialization preceeds static initialization 13*f4a2713aSLionel Sambuc void f() { 14*f4a2713aSLionel Sambuc constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}} 15*f4a2713aSLionel Sambuc } 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc constexpr B b1; // expected-error {{requires a user-provided default constructor}} 18*f4a2713aSLionel Sambuc constexpr B b2 = B(); // ok 19*f4a2713aSLionel Sambuc static_assert(b2.a.a == 1, ""); 20*f4a2713aSLionel Sambuc static_assert(b2.a.b == 2, ""); 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc struct C { 23*f4a2713aSLionel Sambuc int c; 24*f4a2713aSLionel Sambuc }; 25*f4a2713aSLionel Sambuc struct D : C { int d; }; 26*f4a2713aSLionel Sambuc constexpr C c1; // expected-error {{requires a user-provided default constructor}} 27*f4a2713aSLionel Sambuc constexpr C c2 = C(); // ok 28*f4a2713aSLionel Sambuc constexpr D d1; // expected-error {{requires a user-provided default constructor}} 29*f4a2713aSLionel Sambuc constexpr D d2 = D(); // ok with DR1452 30*f4a2713aSLionel Sambuc static_assert(D().c == 0, ""); 31*f4a2713aSLionel Sambuc static_assert(D().d == 0, ""); 32*f4a2713aSLionel Sambuc 33*f4a2713aSLionel Sambuc struct V : virtual C {}; 34*f4a2713aSLionel Sambuc template<typename T> struct Z : T { 35*f4a2713aSLionel Sambuc constexpr Z() : V() {} 36*f4a2713aSLionel Sambuc }; 37*f4a2713aSLionel Sambuc constexpr int n = Z<V>().c; // expected-error {{constant expression}} expected-note {{virtual base class}} 38