1f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
27881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian
37881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanianclass S {
47881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanianpublic:
57881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian  S ();
67881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian};
77881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian
87881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanianstruct D : S {
9ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson  D() :
10ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    b1(0), // expected-note {{previous initialization is here}}
11ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    b2(1),
12ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    b1(0), // expected-error {{multiple initializations given for non-static member 'b1'}}
13ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    S(),   // expected-note {{previous initialization is here}}
14ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    S()    // expected-error {{multiple initializations given for base 'S'}}
15ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    {}
167881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian  int b1;
177881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian  int b2;
187881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian};
197881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian
20ee11b2dd530f3fb873e108f21341626168758a45Anders Carlssonstruct A {
21ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson  struct {
22ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    int a;
23ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson    int b;
24ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson  };
25ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson  A();
26ee11b2dd530f3fb873e108f21341626168758a45Anders Carlsson};
277881a0565893f1da6faafbd86377f5b50e4376a5Fariborz Jahanian
28ee11b2dd530f3fb873e108f21341626168758a45Anders CarlssonA::A() : a(10), b(20) { }
29ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson
30ea356fb65cc844abeab1176f6333a86b69644735Anders Carlssonnamespace Test1 {
31ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson  template<typename T> struct A {};
32ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson  template<typename T> struct B : A<T> {
33ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson
34ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson    B() : A<T>(), // expected-note {{previous initialization is here}}
35ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson      A<T>() { } // expected-error {{multiple initializations given for base 'A<T>'}}
36ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson  };
37ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson}
38ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson
39ea356fb65cc844abeab1176f6333a86b69644735Anders Carlssonnamespace Test2 {
40ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson  template<typename T> struct A : T {
41ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson    A() : T(), // expected-note {{previous initialization is here}}
42ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson      T() { } // expected-error {{multiple initializations given for base 'T'}}
43ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson  };
44ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson}
45ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson
46ea356fb65cc844abeab1176f6333a86b69644735Anders Carlssonnamespace Test3 {
47ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson  template<typename T> struct A {
48ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson    T t;
49ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson
50ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson    A() : t(1), // expected-note {{previous initialization is here}}
51ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson      t(2) { } // expected-error {{multiple initializations given for non-static member 't'}}
52ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson  };
53ea356fb65cc844abeab1176f6333a86b69644735Anders Carlsson}
543c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall
553c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCallnamespace test4 {
563c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall  class A {
573c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall    union {
583c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall      struct {
593c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall        int a;
603c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall        int b;
613c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall      };
623c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall
633c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall      int c;
643c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall
653c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall      union {
663c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall        int d;
673c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall        int e;
683c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall      };
693c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall    };
703c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall
713c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall    A(char _) : a(0), b(0) {}
726fe2965ce722826ae7c3af85271f900286ef20c3David Blaikie    A(short _) : a(0), c(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}}
736fe2965ce722826ae7c3af85271f900286ef20c3David Blaikie    A(int _) : d(0), e(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}}
746fe2965ce722826ae7c3af85271f900286ef20c3David Blaikie    A(long _) : a(0), d(0) {} // expected-error {{initializing multiple members of union}} expected-note {{previous initialization is here}}
753c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall  };
763c3ccdbe73cb43bdf39a9102f5f7eb842fb71952John McCall}
77f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie
78f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikienamespace test5 {
79f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie  struct Base {
80f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie    Base(int);
81f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie  };
82f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie  struct A : Base {
83f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie    A() : decltype(Base(1))(3) {
84f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie    }
85f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie    A(int) : Base(3), // expected-note {{previous initialization is here}}
86f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie             decltype(Base(1))(2), // expected-error {{multiple initializations given for base 'decltype(test5::Base(1))' (aka 'test5::Base')}}
87f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie             decltype(int())() { // expected-error {{constructor initializer 'decltype(int())' (aka 'int') does not name a class}}
88f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie    }
89f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie    A(float) : decltype(A())(3) {
90f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie    }
91f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie  };
92f211662199c87461f3b1475a549ab439c63ca83bDavid Blaikie}
93dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregor
94dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregornamespace rdar13185264 {
95dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregor  class X {
96dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregor    X() : a(), // expected-note{{previous initialization is here}}
97dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregor          a()  { } // expected-error{{multiple initializations given for non-static member 'a'}}
98dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregor    union { void *a; };
99dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregor  };
100dc392c1bae3306af7aec25f0b0b14637d2dc6b39Douglas Gregor}
101cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman
102cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedmannamespace PR16596 {
103cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman  class A { public: virtual ~A(); };
104cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman  typedef const A Foo;
105cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman  void Apply(Foo processor);
106cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman  struct Bar : public Foo {};
107cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman  void Fetch() {
108cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman    Apply(Bar());
109cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman  }
110cf2901abf346c64792e3beb1e7dfeecff0b313f7Eli Friedman}
111