blob: 2cdca829ffb9615e817c257257a14ff8ca6e37f2 [file] [log] [blame]
David Blaikief2116622012-01-24 06:03:59 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
Fariborz Jahanian7881a052009-06-29 22:33:26 +00002
3class S {
4public:
5 S ();
6};
7
8struct D : S {
Anders Carlssonee11b2d2010-03-30 16:19:37 +00009 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 Jahanian7881a052009-06-29 22:33:26 +000016 int b1;
17 int b2;
Fariborz Jahanian7881a052009-06-29 22:33:26 +000018};
19
Anders Carlssonee11b2d2010-03-30 16:19:37 +000020struct A {
21 struct {
22 int a;
23 int b;
24 };
25 A();
26};
Fariborz Jahanian7881a052009-06-29 22:33:26 +000027
Anders Carlssonee11b2d2010-03-30 16:19:37 +000028A::A() : a(10), b(20) { }
Anders Carlssonea356fb2010-04-02 05:42:15 +000029
30namespace 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
39namespace 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
46namespace 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 McCall3c3ccdb2010-04-10 09:28:51 +000054
55namespace 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 Blaikie6fe29652011-11-17 06:01:57 +000072 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 McCall3c3ccdb2010-04-10 09:28:51 +000075 };
76}
David Blaikief2116622012-01-24 06:03:59 +000077
78namespace 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}
Douglas Gregordc392c12013-03-25 23:28:23 +000093
94namespace rdar13185264 {
95 class X {
96 X() : a(), // expected-note{{previous initialization is here}}
97 a() { } // expected-error{{multiple initializations given for non-static member 'a'}}
98 union { void *a; };
99 };
100}