1 // RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify
4 constexpr A() : a(b
+ 1), b(a
+ 1) {} // expected-note 5{{outside its lifetime}}
8 struct B
{ // expected-note {{in call to 'A()'}}
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()'}}
15 constexpr A a
; // expected-error {{constant expression}} expected-note {{in call to 'A()'}}
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, "");
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, "");
34 struct V
: virtual C
{};
35 template<typename T
> struct Z
: T
{
36 constexpr Z() : V() {}
38 constexpr int n
= Z
<V
>().c
; // expected-error {{constant expression}} expected-note {{non-literal type 'Z<V>'}}
40 struct E
{ // expected-note {{in call to 'A()'}}
43 constexpr E e1
; // expected-error {{constant expression}} expected-note {{in call to '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, "");
50 namespace InvalidDeclInsideConstExpr
{
51 template <int a
> struct i
; // expected-note {{template is declared here}}
52 template <> struct i
<0> {};
54 template <int x
> constexpr auto c() {
55 // i<x> is valid, but it might be incomplete. g would be invalid in that case.
56 i
<x
> g
; // expected-error {{implicit instantiation of undefined template 'InvalidDeclInsideConstExpr::i<1>'}}
60 auto y
= c
<1>(); // expected-note {{in instantiation of function template specialization 'InvalidDeclInsideConstExpr::c<1>' requested here}}
61 auto x
= c
<0>(); // this is valid.