• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 
3 struct X1 { // has no implicit default constructor
4    X1(int);
5 };
6 
7 struct X2  : X1 {  // expected-note 2 {{'X2' declared here}}
8    X2(int);
9 };
10 
11 struct X3 : public X2 { // expected-error {{implicit default constructor for 'X3' must explicitly initialize the base class 'X2' which does not have a default constructor}}
12 };
13 X3 x3; // expected-note {{first required here}}
14 
15 
16 struct X4 { // expected-error {{must explicitly initialize the member 'x2'}} \
17             // expected-error {{must explicitly initialize the reference member 'rx2'}}
18   X2 x2; 	// expected-note {{member is declared here}}
19   X2 & rx2; // expected-note {{declared here}}
20 };
21 
22 X4 x4; // expected-note {{first required here}}
23 
24 
25 struct Y1 { // has no implicit default constructor
26    Y1(int);
27 };
28 
29 struct Y2  : Y1 {
30    Y2(int);
31    Y2();
32 };
33 
34 struct Y3 : public Y2 {
35 };
36 Y3 y3;
37 
38 struct Y4 {
39   Y2 y2;
40 };
41 
42 Y4 y4;
43 
44 // More tests
45 
46 struct Z1 { // expected-error {{must explicitly initialize the reference member 'z'}} \
47             // expected-error {{must explicitly initialize the const member 'c1'}}
48   int& z;       // expected-note {{declared here}}
49   const int c1; // expected-note {{declared here}}
50   volatile int v1;
51 };
52 
53 // Test default initialization which *requires* a constructor call for non-POD.
54 Z1 z1; // expected-note {{first required here}}
55 
56 // Ensure that value initialization doesn't use trivial implicit constructors.
57 namespace PR7948 {
58   // Note that this is also non-POD to ensure we don't just special case PODs.
59   struct S { const int x; ~S(); };
60   const S arr[2] = { { 42 } };
61 }
62 
63 // This is valid
64 union U {
65   const int i;
66   float f;
67 };
68 U u;
69