Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 2 | |
| 3 | struct X1 { // has no implicit default constructor |
| 4 | X1(int); |
| 5 | }; |
| 6 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 7 | struct X2 : X1 { // expected-note 2 {{'X2' declared here}} |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 8 | X2(int); |
| 9 | }; |
| 10 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 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}} |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 12 | }; |
Eli Friedman | 80c30da | 2009-11-09 19:20:36 +0000 | [diff] [blame] | 13 | X3 x3; // expected-note {{first required here}} |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 14 | |
| 15 | |
Eli Friedman | 49c16da | 2009-11-09 01:05:47 +0000 | [diff] [blame] | 16 | struct X4 { // expected-error {{must explicitly initialize the member 'x2'}} \ |
| 17 | // expected-error {{must explicitly initialize the reference member 'rx2'}} |
Fariborz Jahanian | 0c728f1 | 2009-10-08 22:15:49 +0000 | [diff] [blame] | 18 | X2 x2; // expected-note {{member is declared here}} |
Anders Carlsson | d1aa800 | 2010-04-23 02:20:12 +0000 | [diff] [blame] | 19 | X2 & rx2; // expected-note {{declared here}} |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 20 | }; |
| 21 | |
Eli Friedman | 80c30da | 2009-11-09 19:20:36 +0000 | [diff] [blame] | 22 | X4 x4; // expected-note {{first required here}} |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 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 | |
Eli Friedman | 49c16da | 2009-11-09 01:05:47 +0000 | [diff] [blame] | 46 | struct Z1 { // expected-error {{must explicitly initialize the reference member 'z'}} \ |
| 47 | // expected-error {{must explicitly initialize the const member 'c1'}} |
Anders Carlsson | d1aa800 | 2010-04-23 02:20:12 +0000 | [diff] [blame] | 48 | int& z; // expected-note {{declared here}} |
| 49 | const int c1; // expected-note {{declared here}} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 50 | volatile int v1; |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
Chandler Carruth | 4e6fbce | 2010-08-23 07:55:51 +0000 | [diff] [blame] | 53 | // Test default initialization which *requires* a constructor call for non-POD. |
Eli Friedman | 80c30da | 2009-11-09 19:20:36 +0000 | [diff] [blame] | 54 | Z1 z1; // expected-note {{first required here}} |
Fariborz Jahanian | 3da83eb | 2009-06-20 20:23:38 +0000 | [diff] [blame] | 55 | |
Chandler Carruth | 4e6fbce | 2010-08-23 07:55:51 +0000 | [diff] [blame] | 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 | } |
Sean Hunt | 1f2f384 | 2011-05-17 00:19:05 +0000 | [diff] [blame] | 62 | |
| 63 | // This is valid |
| 64 | union U { |
| 65 | const int i; |
| 66 | float f; |
| 67 | }; |
| 68 | U u; |