1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
3 // Implicitly-defined default constructors are constexpr if the implicit
4 // definition would be.
5 struct NonConstexpr1
{ // expected-note {{here}}
8 struct NonConstexpr2
{ // expected-note {{here}}
11 struct NonConstexpr2a
: NonConstexpr1
{ };
12 constexpr NonConstexpr1 nc1
= NonConstexpr1(); // ok, does not call constructor
13 constexpr NonConstexpr2 nc2
= NonConstexpr2(); // ok, does not call constructor
14 constexpr NonConstexpr2a nc2a
= NonConstexpr2a(); // ok, does not call constructor
15 constexpr int nc2_a
= NonConstexpr2().nl
.a
; // ok
16 constexpr int nc2a_a
= NonConstexpr2a().a
; // ok
18 friend constexpr NonConstexpr1::NonConstexpr1(); // expected-error {{follows non-constexpr declaration}}
19 friend constexpr NonConstexpr2::NonConstexpr2(); // expected-error {{follows non-constexpr declaration}}
23 constexpr Constexpr1 c1
= Constexpr1(); // ok
24 struct NonConstexpr3
: virtual Constexpr1
{}; // expected-note {{struct with virtual base}} expected-note {{declared here}}
25 constexpr NonConstexpr3 nc3
= NonConstexpr3(); // expected-error {{non-literal type 'const NonConstexpr3'}}
30 constexpr Constexpr2 c2
= Constexpr2(); // ok
35 constexpr Member(int&a
) : a(a
) {}
38 struct NonConstexpr4
{ // expected-note {{here}}
41 constexpr NonConstexpr4 nc4
= NonConstexpr4(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr4'}}
43 constexpr Constexpr3() : m(n
) {}
46 constexpr Constexpr3 c3
= Constexpr3(); // ok
50 constexpr Constexpr4 c4
= Constexpr4(); // ok
53 // This rule breaks some legal C++98 programs!
54 struct A
{}; // expected-note {{here}}
56 friend A::A(); // expected-error {{non-constexpr declaration of 'A' follows constexpr declaration}}
59 namespace UnionCtors
{
60 union A
{ // expected-note {{here}}
82 struct E
{ // expected-note {{here}}
90 friend constexpr A::A() noexcept
; // expected-error {{follows non-constexpr declaration}}
91 friend constexpr B::B() noexcept
;
92 friend constexpr C::C() noexcept
;
93 friend constexpr D::D() noexcept
;
94 friend constexpr E::E() noexcept
; // expected-error {{follows non-constexpr declaration}}
99 // FIXME: We implement a speculative wording fix here: if a class inherits a
100 // default constructor and doesn't declare one itself, we declare an default
101 // constructor implicitly. This allows us to meanignfully reason about
102 // whether that default constructor is constexpr, trivial, and so on.
103 struct A
{ constexpr A() {} };
112 struct E
: D
{ using D::D
; E(int); };
113 static_assert(E().n
== 0, "");
114 static_assert(E
{}.n
== 0, "");
117 static_assert(F().e
.n
== 0, "");
118 static_assert(F
{}.e
.n
== 0, "");
121 U u
; // OK, trivial default constructor
124 struct H
: D
{ using D::D
; H(int); G g
; };
125 union V
{ H h
; }; // expected-note {{field 'h' has a non-trivial default constructor}}
126 V v
; // expected-error {{deleted}}