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