brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 25c7064 Raw
120 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s4 5struct X1 { // has no implicit default constructor6   X1(int);7};8 9struct X2  : X1 {10#if __cplusplus <= 199711L11// expected-note@-2 2 {{'X2' declared here}}12#endif13 14   X2(int);15};16 17struct X3 : public X2 {18#if __cplusplus <= 199711L19// expected-error@-2 {{implicit default constructor for 'X3' must explicitly initialize the base class 'X2' which does not have a default constructor}}20#else21// expected-note@-4 {{default constructor of 'X3' is implicitly deleted because base class 'X2' has no default constructor}}22#endif23};24 25X3 x3;26#if __cplusplus <= 199711L27// expected-note@-2 {{first required here}}28#else29// expected-error@-4 {{call to implicitly-deleted default constructor of 'X3'}}30#endif31 32struct X4 {33#if __cplusplus <= 199711L34// expected-error@-2 {{must explicitly initialize the member 'x2'}}35// expected-error@-3 {{must explicitly initialize the reference member 'rx2'}}36#endif37 38  X2 x2;39#if __cplusplus <= 199711L40  // expected-note@-2 {{member is declared here}}41#else42  // expected-note@-4 {{default constructor of 'X4' is implicitly deleted because field 'x2' has no default constructor}}43#endif44 45  X2 & rx2;46#if __cplusplus <= 199711L47  // expected-note@-2 {{declared here}}48#endif49};50 51X4 x4;52#if __cplusplus <= 199711L53// expected-note@-2 {{first required here}}54#else55// expected-error@-4 {{call to implicitly-deleted default constructor of 'X4'}}56#endif57 58struct Y1 { // has no implicit default constructor59   Y1(int);60};61 62struct Y2  : Y1 { 63   Y2(int);64   Y2();65};66 67struct Y3 : public Y2 {68};69Y3 y3; 70 71struct Y4 {72  Y2 y2; 73};74 75Y4 y4;76 77// More tests78 79struct Z1 {80#if __cplusplus <= 199711L81// expected-error@-2 {{must explicitly initialize the reference member 'z'}}82// expected-error@-3 {{must explicitly initialize the const member 'c1'}}83#endif84 85  int& z;86#if __cplusplus <= 199711L87  // expected-note@-2 {{declared here}}88#else89  // expected-note@-4 {{default constructor of 'Z1' is implicitly deleted because field 'z' of reference type 'int &' would not be initialized}}90#endif91 92  const int c1;93#if __cplusplus <= 199711L94  // expected-note@-2 {{declared here}}95#endif96  volatile int v1;97};98 99// Test default initialization which *requires* a constructor call for non-POD.100Z1 z1;101#if __cplusplus <= 199711L102// expected-note@-2 {{first required here}}103#else104// expected-error@-4 {{call to implicitly-deleted default constructor of 'Z1'}}105#endif106 107// Ensure that value initialization doesn't use trivial implicit constructors.108namespace PR7948 {109  // Note that this is also non-POD to ensure we don't just special case PODs.110  struct S { const int x; ~S(); };111  const S arr[2] = { { 42 } };112}113 114// This is valid115union U {116  const int i;117  float f;118};119U u;120