• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {{outside its lifetime}}
5   int a;
6   int b;
7 };
8 struct B {
9   A a;
10 };
11 
12 constexpr A a; // ok, zero initialization precedes static initialization
f()13 void f() {
14   constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}}
15 }
16 
17 constexpr B b1; // ok
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 {{without a user-provided default constructor}}
27 constexpr C c2 = C(); // ok
28 constexpr D d1; // expected-error {{without a user-provided default constructor}}
29 constexpr D d2 = D(); // ok with DR1452
30 static_assert(D().c == 0, "");
31 static_assert(D().d == 0, "");
32 
33 struct V : virtual C {};
34 template<typename T> struct Z : T {
ZZ35   constexpr Z() : V() {}
36 };
37 constexpr int n = Z<V>().c; // expected-error {{constant expression}} expected-note {{virtual base class}}
38