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/class-base-member-init.cpp | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/SemaCXX/class-base-member-init.cpp')
-rw-r--r-- | clang/test/SemaCXX/class-base-member-init.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/class-base-member-init.cpp b/clang/test/SemaCXX/class-base-member-init.cpp new file mode 100644 index 0000000..e84e57b --- /dev/null +++ b/clang/test/SemaCXX/class-base-member-init.cpp @@ -0,0 +1,92 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s + +class S { +public: + S (); +}; + +struct D : S { + D() : + b1(0), // expected-note {{previous initialization is here}} + b2(1), + b1(0), // expected-error {{multiple initializations given for non-static member 'b1'}} + S(), // expected-note {{previous initialization is here}} + S() // expected-error {{multiple initializations given for base 'S'}} + {} + int b1; + int b2; +}; + +struct A { + struct { + int a; + int b; + }; + A(); +}; + +A::A() : a(10), b(20) { } + +namespace Test1 { + template<typename T> struct A {}; + template<typename T> struct B : A<T> { + + B() : A<T>(), // expected-note {{previous initialization is here}} + A<T>() { } // expected-error {{multiple initializations given for base 'A<T>'}} + }; +} + +namespace Test2 { + template<typename T> struct A : T { + A() : T(), // expected-note {{previous initialization is here}} + T() { } // expected-error {{multiple initializations given for base 'T'}} + }; +} + +namespace Test3 { + template<typename T> struct A { + T t; + + A() : t(1), // expected-note {{previous initialization is here}} + t(2) { } // expected-error {{multiple initializations given for non-static member 't'}} + }; +} + +namespace test4 { + class A { + union { + struct { + int a; + int b; + }; + + int c; + + union { + int d; + int e; + }; + }; + + A(char _) : a(0), b(0) {} + A(short _) : a(0), c(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}} + A(int _) : d(0), e(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}} + A(long _) : a(0), d(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}} + }; +} + +namespace test5 { + struct Base { + Base(int); + }; + struct A : Base { + A() : decltype(Base(1))(3) { + } + A(int) : Base(3), // expected-note {{previous initialization is here}} + decltype(Base(1))(2), // expected-error {{multiple initializations given for base 'decltype(test5::Base(1))' (aka 'test5::Base')}} + decltype(int())() { // expected-error {{constructor initializer 'decltype(int())' (aka 'int') does not name a class}} + } + A(float) : decltype(A())(3) { + } + }; +} |