brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · e24b7f7 Raw
74 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -Wno-deprecated-builtins -std=c++98 %s2// RUN: %clang_cc1 -fsyntax-only -verify -Wno-deprecated-builtins -std=c++11 %s3// RUN: %clang_cc1 -fsyntax-only -verify -Wno-deprecated-builtins %s4 5//   A program that calls for default-initialization or value-initialization of6//   an entity of reference type is illformed. If T is a cv-qualified type, the7//   cv-unqualified version of T is used for these definitions of8//   zero-initialization, default-initialization, and value-initialization.9 10typedef int &IR;11IR r; // expected-error {{declaration of reference variable 'r' requires an initializer}}12int n = IR(); // expected-error {{reference to type 'int' requires an initializer}}13 14#if __cplusplus < 201103L15struct 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}}17};18S s; // expected-note {{implicit default constructor for 'S' first required here}}19S f() {20  return S(); // expected-note {{in value-initialization of type 'S' here}}21}22 23struct T24  : S { // expected-note 2{{in value-initialization of type 'S' here}}25};26T t = T(); // expected-note {{in value-initialization of type 'T' here}}27 28struct U {29  T t[3]; // expected-note {{in value-initialization of type 'T' here}}30};31U u = U(); // expected-note {{in value-initialization of type 'U' here}}32#else33struct S {34  int &x; // expected-note 4{{because field 'x' of reference type 'int &' would not be initialized}}35};36S s; // expected-error {{deleted default constructor}}37S f() {38  return S(); // expected-error {{deleted default constructor}}39}40 41struct T42  : S { // expected-note 2{{because base class 'S' has a deleted default constructor}}43};44T t = T(); // expected-error {{deleted default constructor}}45 46struct U {47  T t[3]; // expected-note {{because field 't' has a deleted default constructor}}48};49U u = U(); // expected-error {{deleted default constructor}}50#endif51 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 we54// recursively apply the value-initialization checks, but we will emit a55// constructor call anyway, because the default constructor is not trivial.56struct V {57  int n;58  int &r = n; // expected-warning 0-1{{C++11}}59};60V v = V(); // ok61struct W {62  int n;63  S s = { n }; // expected-warning 0-1{{C++11}}64};65W w = W(); // ok66 67// Ensure we're not faking this up by making the default constructor68// non-trivial.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), "");74