summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/warn-reorder-ctor-initialization.cpp
blob: 2634202172a2b8624a18453ed799e11286cf3083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// RUN: %clang_cc1  -fsyntax-only -Wreorder -verify %s

struct BB {};

struct BB1 {};

class complex : public BB, BB1 { 
public: 
  complex() : s2(1),  // expected-warning {{member 's2' will be initialized after}}
              s1(1) , // expected-note {{field s1}} 
              s3(3),  // expected-warning {{member 's3' will be initialized after}} 
              BB1(),   // expected-note {{base 'BB1'}}  \
                      // expected-warning {{base class 'BB1' will be initialized after}}
              BB() {}  // expected-note {{base 'BB'}}
  int s1;
  int s2;
  int s3;
}; 


// testing virtual bases.


struct V { 
  V();
};

struct A : public virtual V { 
  A(); 
};

struct B : public virtual V {
  B(); 
};

struct Diamond : public A, public B {
  Diamond() : A(), B() {}
};


struct C : public A, public B, private virtual V { 
  C() { }
};


struct D : public A, public B { 
  D()  : A(), V() {   } // expected-warning {{base class 'A' will be initialized after}} \
                        // expected-note {{base 'V'}}
};


struct E : public A, public B, private virtual V { 
  E()  : A(), V() {  } // expected-warning {{base class 'A' will be initialized after}} \
                       // expected-note {{base 'V'}}
};


struct A1  { 
  A1(); 
};

struct B1 {
  B1();
};

struct F : public A1, public B1, private virtual V { 
  F()  : A1(), V() {  } // expected-warning {{base class 'A1' will be initialized after}} \
                        // expected-note {{base 'V'}}
};

struct X : public virtual A, virtual V, public virtual B {
  X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after}} \
                        // expected-note {{base 'V'}}
};

class Anon {
  int c; union {int a,b;}; int d;
  Anon() : c(10), b(1), d(2) {}
};
class Anon2 {
  int c; union {int a,b;}; int d;
  Anon2() : c(2),
            d(10), // expected-warning {{member 'd' will be initialized after}}
            b(1) {} // expected-note {{field b}}
};
class Anon3 {
  union {int a,b;};
  Anon3() : b(1) {}
};
OpenPOWER on IntegriCloud