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