[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / class-base-member-init.cpp
bloba6bb4410a81c84e9227ae75503693d1aff32fe33
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
3 class S {
4 public:
5 S ();
6 };
8 struct D : S {
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'}}
16 int b1;
17 int b2;
20 struct A {
21 struct {
22 int a;
23 int b;
25 A();
28 A::A() : a(10), b(20) { }
30 namespace Test1 {
31 template<typename T> struct A {};
32 template<typename T> struct B : A<T> {
34 B() : A<T>(), // expected-note {{previous initialization is here}}
35 A<T>() { } // expected-error {{multiple initializations given for base 'A<T>'}}
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'}}
46 namespace Test3 {
47 template<typename T> struct A {
48 T t;
50 A() : t(1), // expected-note {{previous initialization is here}}
51 t(2) { } // expected-error {{multiple initializations given for non-static member 't'}}
55 namespace test4 {
56 class A {
57 union {
58 struct {
59 int a;
60 int b;
63 int c;
65 union {
66 int d;
67 int e;
71 A(char _) : a(0), b(0) {}
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}}
78 namespace test5 {
79 struct Base {
80 Base(int);
82 struct A : Base {
83 A() : decltype(Base(1))(3) {
85 A(int) : Base(3), // expected-note {{previous initialization is here}}
86 decltype(Base(1))(2), // expected-error {{multiple initializations given for base 'decltype(Base(1))' (aka 'test5::Base')}}
87 decltype(int())() { // expected-error {{constructor initializer 'decltype(int())' (aka 'int') does not name a class}}
89 A(float) : decltype(A())(3) {
94 namespace 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; };
102 namespace PR16596 {
103 class A { public: virtual ~A(); };
104 typedef const A Foo;
105 void Apply(Foo processor);
106 struct Bar : public Foo {};
107 void Fetch() {
108 Apply(Bar());