Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1  -fsyntax-only -Wreorder -verify %s
      2 
      3 struct BB {};
      4 
      5 struct BB1 {};
      6 
      7 class complex : public BB, BB1 {
      8 public:
      9   complex()
     10     : s2(1), // expected-warning {{field 's2' will be initialized after field 's1'}}
     11       s1(1),
     12       s3(3), // expected-warning {{field 's3' will be initialized after base 'BB1'}}
     13       BB1(), // expected-warning {{base class 'BB1' will be initialized after base 'BB'}}
     14       BB()
     15   {}
     16   int s1;
     17   int s2;
     18   int s3;
     19 };
     20 
     21 
     22 // testing virtual bases.
     23 
     24 
     25 struct V {
     26   V();
     27 };
     28 
     29 struct A : public virtual V {
     30   A();
     31 };
     32 
     33 struct B : public virtual V {
     34   B();
     35 };
     36 
     37 struct Diamond : public A, public B {
     38   Diamond() : A(), B() {}
     39 };
     40 
     41 
     42 struct C : public A, public B, private virtual V {
     43   C() { }
     44 };
     45 
     46 
     47 struct D : public A, public B {
     48   D()  : A(), V() {   } // expected-warning {{base class 'A' will be initialized after base 'V'}}
     49 };
     50 
     51 
     52 struct E : public A, public B, private virtual V {
     53   E()  : A(), V() {  } // expected-warning {{base class 'A' will be initialized after base 'V'}}
     54 };
     55 
     56 
     57 struct A1  {
     58   A1();
     59 };
     60 
     61 struct B1 {
     62   B1();
     63 };
     64 
     65 struct F : public A1, public B1, private virtual V {
     66   F()  : A1(), V() {  } // expected-warning {{base class 'A1' will be initialized after base 'V'}}
     67 };
     68 
     69 struct X : public virtual A, virtual V, public virtual B {
     70   X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after base 'V'}}
     71 };
     72 
     73 class Anon {
     74   int c; union {int a,b;}; int d;
     75   Anon() : c(10), b(1), d(2) {}
     76 };
     77 class Anon2 {
     78   int c; union {int a,b;}; int d;
     79   Anon2() : c(2),
     80             d(10), // expected-warning {{field 'd' will be initialized after field 'b'}}
     81             b(1) {}
     82 };
     83 class Anon3 {
     84   union {int a,b;};
     85   Anon3() : b(1) {}
     86 };
     87 
     88 namespace T1 {
     89 
     90 struct S1 { };
     91 struct S2: virtual S1 { };
     92 struct S3 { };
     93 
     94 struct S4: virtual S3, S2 {
     95   S4() : S2(), // expected-warning {{base class 'T1::S2' will be initialized after base 'T1::S3'}}
     96     S3() { };
     97 };
     98 }
     99 
    100 namespace test2 {
    101   struct Foo { Foo(); };
    102   class A {
    103     template <class T> A(T *t) :
    104       y(),  // expected-warning {{field 'y' will be initialized after field 'x'}}
    105       x()
    106     {}
    107     Foo x;
    108     Foo y;
    109   };
    110 }
    111 
    112 // PR6575: this should not crash
    113 namespace test3 {
    114   struct MyClass {
    115     MyClass() : m_int(0) {}
    116     union {
    117       struct {
    118         int m_int;
    119       };
    120     };
    121   };
    122 }
    123 
    124 namespace PR7179 {
    125   struct X
    126   {
    127     struct Y
    128     {
    129       template <class T> Y(T x) : X(x) { }
    130     };
    131   };
    132 }
    133