1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-deprecated-builtins -std=c++98 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-deprecated-builtins -std=c++11 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-deprecated-builtins %s
5 // A program that calls for default-initialization or value-initialization of
6 // an entity of reference type is illformed. If T is a cv-qualified type, the
7 // cv-unqualified version of T is used for these definitions of
8 // zero-initialization, default-initialization, and value-initialization.
11 IR r
; // expected-error {{declaration of reference variable 'r' requires an initializer}}
12 int n
= IR(); // expected-error {{reference to type 'int' requires an initializer}}
14 #if __cplusplus < 201103L
15 struct S
{ // expected-error {{implicit default constructor for 'S' must explicitly initialize the reference member}}
16 int &x
; // expected-note {{declared here}} expected-error 3{{reference to type 'int' requires an initializer}}
18 S s
; // expected-note {{implicit default constructor for 'S' first required here}}
20 return S(); // expected-note {{in value-initialization of type 'S' here}}
24 : S
{ // expected-note 2{{in value-initialization of type 'S' here}}
26 T t
= T(); // expected-note {{in value-initialization of type 'T' here}}
29 T t
[3]; // expected-note {{in value-initialization of type 'T' here}}
31 U u
= U(); // expected-note {{in value-initialization of type 'U' here}}
34 int &x
; // expected-note 4{{because field 'x' of reference type 'int &' would not be initialized}}
36 S s
; // expected-error {{deleted default constructor}}
38 return S(); // expected-error {{deleted default constructor}}
42 : S
{ // expected-note 2{{because base class 'S' has a deleted default constructor}}
44 T t
= T(); // expected-error {{deleted default constructor}}
47 T t
[3]; // expected-note {{because field 't' has a deleted default constructor}}
49 U u
= U(); // expected-error {{deleted default constructor}}
52 // Ensure that we handle C++11 in-class initializers properly as an extension.
53 // In this case, there is no user-declared default constructor, so we
54 // recursively apply the value-initialization checks, but we will emit a
55 // constructor call anyway, because the default constructor is not trivial.
58 int &r
= n
; // expected-warning 0-1{{C++11}}
63 S s
= { n
}; // expected-warning 0-1{{C++11}}
67 // Ensure we're not faking this up by making the default constructor
69 _Static_assert(__has_trivial_constructor(S
), "");
70 _Static_assert(__has_trivial_constructor(T
), "");
71 _Static_assert(__has_trivial_constructor(U
), "");
72 _Static_assert(!__has_trivial_constructor(V
), "");
73 _Static_assert(!__has_trivial_constructor(W
), "");