2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify %s
2009-06-21 04:23:38 +08:00
struct X1 { // has no implicit default constructor
X1 ( int ) ;
} ;
2010-03-10 19:27:22 +08:00
struct X2 : X1 { // expected-note 2 {{'X2' declared here}}
2009-06-21 04:23:38 +08:00
X2 ( int ) ;
} ;
2010-03-10 19:27:22 +08:00
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}}
2009-06-21 04:23:38 +08:00
} ;
2009-11-10 03:20:36 +08:00
X3 x3 ; // expected-note {{first required here}}
2009-06-21 04:23:38 +08:00
2009-11-09 09:05:47 +08:00
struct X4 { / / expected - error { { must explicitly initialize the member ' x2 ' } } \
// expected-error {{must explicitly initialize the reference member 'rx2'}}
2009-10-09 06:15:49 +08:00
X2 x2 ; // expected-note {{member is declared here}}
2010-04-23 10:20:12 +08:00
X2 & rx2 ; // expected-note {{declared here}}
2009-06-21 04:23:38 +08:00
} ;
2009-11-10 03:20:36 +08:00
X4 x4 ; // expected-note {{first required here}}
2009-06-21 04:23:38 +08:00
struct Y1 { // has no implicit default constructor
Y1 ( int ) ;
} ;
struct Y2 : Y1 {
Y2 ( int ) ;
Y2 ( ) ;
} ;
struct Y3 : public Y2 {
} ;
Y3 y3 ;
struct Y4 {
Y2 y2 ;
} ;
Y4 y4 ;
// More tests
2009-11-09 09:05:47 +08:00
struct Z1 { / / expected - error { { must explicitly initialize the reference member ' z ' } } \
// expected-error {{must explicitly initialize the const member 'c1'}}
2010-04-23 10:20:12 +08:00
int & z ; // expected-note {{declared here}}
const int c1 ; // expected-note {{declared here}}
2009-09-09 23:08:12 +08:00
volatile int v1 ;
2009-06-21 04:23:38 +08:00
} ;
2010-08-23 15:55:51 +08:00
// Test default initialization which *requires* a constructor call for non-POD.
2009-11-10 03:20:36 +08:00
Z1 z1 ; // expected-note {{first required here}}
2009-06-21 04:23:38 +08:00
2010-08-23 15:55:51 +08:00
// Ensure that value initialization doesn't use trivial implicit constructors.
namespace PR7948 {
// Note that this is also non-POD to ensure we don't just special case PODs.
struct S { const int x ; ~ S ( ) ; } ;
const S arr [ 2 ] = { { 42 } } ;
}
2011-05-17 08:19:05 +08:00
// This is valid
union U {
const int i ;
float f ;
} ;
U u ;