1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li
3*67e74705SXin Li // A program that calls for default-initialization or value-initialization of
4*67e74705SXin Li // an entity of reference type is illformed. If T is a cv-qualified type, the
5*67e74705SXin Li // cv-unqualified version of T is used for these definitions of
6*67e74705SXin Li // zero-initialization, default-initialization, and value-initialization.
7*67e74705SXin Li
8*67e74705SXin Li struct S { // expected-error {{implicit default constructor for 'S' must explicitly initialize the reference member}}
9*67e74705SXin Li int &x; // expected-note {{declared here}} expected-error 3{{reference to type 'int' requires an initializer}}
10*67e74705SXin Li };
11*67e74705SXin Li S s; // expected-note {{implicit default constructor for 'S' first required here}}
f()12*67e74705SXin Li S f() {
13*67e74705SXin Li return S(); // expected-note {{in value-initialization of type 'S' here}}
14*67e74705SXin Li }
15*67e74705SXin Li
16*67e74705SXin Li struct T
17*67e74705SXin Li : S { // expected-note 2{{in value-initialization of type 'S' here}}
18*67e74705SXin Li };
19*67e74705SXin Li T t = T(); // expected-note {{in value-initialization of type 'T' here}}
20*67e74705SXin Li
21*67e74705SXin Li struct U {
22*67e74705SXin Li T t[3]; // expected-note {{in value-initialization of type 'T' here}}
23*67e74705SXin Li };
24*67e74705SXin Li U u = U(); // expected-note {{in value-initialization of type 'U' here}}
25*67e74705SXin Li
26*67e74705SXin Li // Ensure that we handle C++11 in-class initializers properly as an extension.
27*67e74705SXin Li // In this case, there is no user-declared default constructor, so we
28*67e74705SXin Li // recursively apply the value-initialization checks, but we will emit a
29*67e74705SXin Li // constructor call anyway, because the default constructor is not trivial.
30*67e74705SXin Li struct V {
31*67e74705SXin Li int n;
32*67e74705SXin Li int &r = n; // expected-warning {{C++11}}
33*67e74705SXin Li };
34*67e74705SXin Li V v = V(); // ok
35*67e74705SXin Li struct W {
36*67e74705SXin Li int n;
37*67e74705SXin Li S s = { n }; // expected-warning {{C++11}}
38*67e74705SXin Li };
39*67e74705SXin Li W w = W(); // ok
40*67e74705SXin Li
41*67e74705SXin Li // Ensure we're not faking this up by making the default constructor
42*67e74705SXin Li // non-trivial.
43*67e74705SXin Li #define static_assert(B, S) typedef int assert_failed[(B) ? 1 : -1];
44*67e74705SXin Li static_assert(__has_trivial_constructor(S), "");
45*67e74705SXin Li static_assert(__has_trivial_constructor(T), "");
46*67e74705SXin Li static_assert(__has_trivial_constructor(U), "");
47*67e74705SXin Li static_assert(!__has_trivial_constructor(V), "");
48*67e74705SXin Li static_assert(!__has_trivial_constructor(W), "");
49