diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/SemaCXX/default-constructor-initializers.cpp | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/SemaCXX/default-constructor-initializers.cpp')
-rw-r--r-- | clang/test/SemaCXX/default-constructor-initializers.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/default-constructor-initializers.cpp b/clang/test/SemaCXX/default-constructor-initializers.cpp new file mode 100644 index 0000000..e783f49 --- /dev/null +++ b/clang/test/SemaCXX/default-constructor-initializers.cpp @@ -0,0 +1,68 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct X1 { // has no implicit default constructor + X1(int); +}; + +struct X2 : X1 { // expected-note 2 {{'X2' declared here}} + X2(int); +}; + +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}} +}; +X3 x3; // expected-note {{first required here}} + + +struct X4 { // expected-error {{must explicitly initialize the member 'x2'}} \ + // expected-error {{must explicitly initialize the reference member 'rx2'}} + X2 x2; // expected-note {{member is declared here}} + X2 & rx2; // expected-note {{declared here}} +}; + +X4 x4; // expected-note {{first required here}} + + +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 + +struct Z1 { // expected-error {{must explicitly initialize the reference member 'z'}} \ + // expected-error {{must explicitly initialize the const member 'c1'}} + int& z; // expected-note {{declared here}} + const int c1; // expected-note {{declared here}} + volatile int v1; +}; + +// Test default initialization which *requires* a constructor call for non-POD. +Z1 z1; // expected-note {{first required here}} + +// 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 } }; +} + +// This is valid +union U { + const int i; + float f; +}; +U u; |