blob: e783f4982605942c3adc44d7dc0599eb52b7d644 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +00002
3struct X1 { // has no implicit default constructor
4 X1(int);
5};
6
John McCall7c2342d2010-03-10 11:27:22 +00007struct X2 : X1 { // expected-note 2 {{'X2' declared here}}
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +00008 X2(int);
9};
10
John McCall7c2342d2010-03-10 11:27:22 +000011struct X3 : public X2 { // expected-error {{implicit default constructor for 'X3' must explicitly initialize the base class 'X2' which does not have a default constructor}}
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +000012};
Eli Friedman80c30da2009-11-09 19:20:36 +000013X3 x3; // expected-note {{first required here}}
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +000014
15
Eli Friedman49c16da2009-11-09 01:05:47 +000016struct X4 { // expected-error {{must explicitly initialize the member 'x2'}} \
17 // expected-error {{must explicitly initialize the reference member 'rx2'}}
Fariborz Jahanian0c728f12009-10-08 22:15:49 +000018 X2 x2; // expected-note {{member is declared here}}
Anders Carlssond1aa8002010-04-23 02:20:12 +000019 X2 & rx2; // expected-note {{declared here}}
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +000020};
21
Eli Friedman80c30da2009-11-09 19:20:36 +000022X4 x4; // expected-note {{first required here}}
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +000023
24
25struct Y1 { // has no implicit default constructor
26 Y1(int);
27};
28
29struct Y2 : Y1 {
30 Y2(int);
31 Y2();
32};
33
34struct Y3 : public Y2 {
35};
36Y3 y3;
37
38struct Y4 {
39 Y2 y2;
40};
41
42Y4 y4;
43
44// More tests
45
Eli Friedman49c16da2009-11-09 01:05:47 +000046struct Z1 { // expected-error {{must explicitly initialize the reference member 'z'}} \
47 // expected-error {{must explicitly initialize the const member 'c1'}}
Anders Carlssond1aa8002010-04-23 02:20:12 +000048 int& z; // expected-note {{declared here}}
49 const int c1; // expected-note {{declared here}}
Mike Stump1eb44332009-09-09 15:08:12 +000050 volatile int v1;
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +000051};
52
Chandler Carruth4e6fbce2010-08-23 07:55:51 +000053// Test default initialization which *requires* a constructor call for non-POD.
Eli Friedman80c30da2009-11-09 19:20:36 +000054Z1 z1; // expected-note {{first required here}}
Fariborz Jahanian3da83eb2009-06-20 20:23:38 +000055
Chandler Carruth4e6fbce2010-08-23 07:55:51 +000056// Ensure that value initialization doesn't use trivial implicit constructors.
57namespace 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}
Sean Hunt1f2f3842011-05-17 00:19:05 +000062
63// This is valid
64union U {
65 const int i;
66 float f;
67};
68U u;