summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/class-base-member-init.cpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaCXX/class-base-member-init.cpp
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaCXX/class-base-member-init.cpp')
-rw-r--r--clang/test/SemaCXX/class-base-member-init.cpp92
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) {
+ }
+ };
+}