David Blaikie | f211662 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s |
Fariborz Jahanian | 7881a05 | 2009-06-29 22:33:26 +0000 | [diff] [blame] | 2 | |
| 3 | class S { |
| 4 | public: |
| 5 | S (); |
| 6 | }; |
| 7 | |
| 8 | struct D : S { |
Anders Carlsson | ee11b2d | 2010-03-30 16:19:37 +0000 | [diff] [blame] | 9 | D() : |
| 10 | b1(0), // expected-note {{previous initialization is here}} |
| 11 | b2(1), |
| 12 | b1(0), // expected-error {{multiple initializations given for non-static member 'b1'}} |
| 13 | S(), // expected-note {{previous initialization is here}} |
| 14 | S() // expected-error {{multiple initializations given for base 'S'}} |
| 15 | {} |
Fariborz Jahanian | 7881a05 | 2009-06-29 22:33:26 +0000 | [diff] [blame] | 16 | int b1; |
| 17 | int b2; |
Fariborz Jahanian | 7881a05 | 2009-06-29 22:33:26 +0000 | [diff] [blame] | 18 | }; |
| 19 | |
Anders Carlsson | ee11b2d | 2010-03-30 16:19:37 +0000 | [diff] [blame] | 20 | struct A { |
| 21 | struct { |
| 22 | int a; |
| 23 | int b; |
| 24 | }; |
| 25 | A(); |
| 26 | }; |
Fariborz Jahanian | 7881a05 | 2009-06-29 22:33:26 +0000 | [diff] [blame] | 27 | |
Anders Carlsson | ee11b2d | 2010-03-30 16:19:37 +0000 | [diff] [blame] | 28 | A::A() : a(10), b(20) { } |
Anders Carlsson | ea356fb | 2010-04-02 05:42:15 +0000 | [diff] [blame] | 29 | |
| 30 | namespace Test1 { |
| 31 | template<typename T> struct A {}; |
| 32 | template<typename T> struct B : A<T> { |
| 33 | |
| 34 | B() : A<T>(), // expected-note {{previous initialization is here}} |
| 35 | A<T>() { } // expected-error {{multiple initializations given for base 'A<T>'}} |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | namespace Test2 { |
| 40 | template<typename T> struct A : T { |
| 41 | A() : T(), // expected-note {{previous initialization is here}} |
| 42 | T() { } // expected-error {{multiple initializations given for base 'T'}} |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | namespace Test3 { |
| 47 | template<typename T> struct A { |
| 48 | T t; |
| 49 | |
| 50 | A() : t(1), // expected-note {{previous initialization is here}} |
| 51 | t(2) { } // expected-error {{multiple initializations given for non-static member 't'}} |
| 52 | }; |
| 53 | } |
John McCall | 3c3ccdb | 2010-04-10 09:28:51 +0000 | [diff] [blame] | 54 | |
| 55 | namespace test4 { |
| 56 | class A { |
| 57 | union { |
| 58 | struct { |
| 59 | int a; |
| 60 | int b; |
| 61 | }; |
| 62 | |
| 63 | int c; |
| 64 | |
| 65 | union { |
| 66 | int d; |
| 67 | int e; |
| 68 | }; |
| 69 | }; |
| 70 | |
| 71 | A(char _) : a(0), b(0) {} |
David Blaikie | 6fe2965 | 2011-11-17 06:01:57 +0000 | [diff] [blame] | 72 | A(short _) : a(0), c(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}} |
| 73 | A(int _) : d(0), e(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}} |
| 74 | A(long _) : a(0), d(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}} |
John McCall | 3c3ccdb | 2010-04-10 09:28:51 +0000 | [diff] [blame] | 75 | }; |
| 76 | } |
David Blaikie | f211662 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 77 | |
| 78 | namespace test5 { |
| 79 | struct Base { |
| 80 | Base(int); |
| 81 | }; |
| 82 | struct A : Base { |
| 83 | A() : decltype(Base(1))(3) { |
| 84 | } |
| 85 | A(int) : Base(3), // expected-note {{previous initialization is here}} |
| 86 | decltype(Base(1))(2), // expected-error {{multiple initializations given for base 'decltype(test5::Base(1))' (aka 'test5::Base')}} |
| 87 | decltype(int())() { // expected-error {{constructor initializer 'decltype(int())' (aka 'int') does not name a class}} |
| 88 | } |
| 89 | A(float) : decltype(A())(3) { |
| 90 | } |
| 91 | }; |
| 92 | } |