From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaCXX/class-base-member-init.cpp | 92 +++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 clang/test/SemaCXX/class-base-member-init.cpp (limited to 'clang/test/SemaCXX/class-base-member-init.cpp') 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 struct A {}; + template struct B : A { + + B() : A(), // expected-note {{previous initialization is here}} + A() { } // expected-error {{multiple initializations given for base 'A'}} + }; +} + +namespace Test2 { + template struct A : T { + A() : T(), // expected-note {{previous initialization is here}} + T() { } // expected-error {{multiple initializations given for base 'T'}} + }; +} + +namespace Test3 { + template 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) { + } + }; +} -- cgit v1.2.3