| 1 |
// PR c++/19808 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-options "-Wuninitialized -Winit-self" } |
| 4 |
// Largely copied from clang's test/SemaCXX/uninitialized.cpp. |
| 5 |
|
| 6 |
int x; |
| 7 |
struct U { |
| 8 |
U() : b(a) { } |
| 9 |
int &a = x; |
| 10 |
int &b; |
| 11 |
}; |
| 12 |
|
| 13 |
struct T { |
| 14 |
T() : a(b), b(a) { } // { dg-warning "reference .T::b. is not yet bound" } |
| 15 |
int &a, &b; |
| 16 |
}; |
| 17 |
|
| 18 |
struct S { |
| 19 |
S() : a(a) { } // { dg-warning ".S::a. is initialized with itself" } |
| 20 |
int &a; |
| 21 |
}; |
| 22 |
|
| 23 |
struct A { |
| 24 |
int a; |
| 25 |
int b; |
| 26 |
A() { } |
| 27 |
A(int (*)[1]) : b(a) { } // { dg-warning ".A::a. is used uninitialized" } |
| 28 |
A(int (*)[2]) : a(b) { } // { dg-warning ".A::b. is used uninitialized" } |
| 29 |
}; |
| 30 |
|
| 31 |
struct D { |
| 32 |
int a; |
| 33 |
int &b; |
| 34 |
int &c = a; |
| 35 |
int d = b; |
| 36 |
D() : b(a) { } |
| 37 |
}; |
| 38 |
|
| 39 |
struct E { |
| 40 |
int a; |
| 41 |
int get(); |
| 42 |
static int num(); |
| 43 |
E() { } |
| 44 |
E(int) { } |
| 45 |
}; |
| 46 |
|
| 47 |
struct F { |
| 48 |
int a; |
| 49 |
E e; |
| 50 |
int b; |
| 51 |
F(int (*)[1]) : a(e.get()) { } // { dg-warning "member .F::e. is used uninitialized" } |
| 52 |
F(int (*)[2]) : a(e.num()) { } |
| 53 |
F(int (*)[3]) : e(a) { } // { dg-warning "member .F::a. is used uninitialized" } |
| 54 |
F(int (*)[4]) : a(4), e(a) { } |
| 55 |
F(int (*)[5]) : e(b) { } // { dg-warning "member .F::b. is used uninitialized" } |
| 56 |
F(int (*)[6]) : e(b), b(4) { } // { dg-warning "member .F::b. is used uninitialized" } |
| 57 |
}; |
| 58 |
|
| 59 |
struct G { |
| 60 |
G(const A&) { }; |
| 61 |
}; |
| 62 |
|
| 63 |
struct H { |
| 64 |
A a1; |
| 65 |
G g; |
| 66 |
A a2; |
| 67 |
H() : g(a1) { } |
| 68 |
H(int) : g(a2) { } // { dg-bogus "member .H::a2. is used uninitialized" } |
| 69 |
}; |
| 70 |
|
| 71 |
struct I { |
| 72 |
I(int *) { } |
| 73 |
}; |
| 74 |
|
| 75 |
struct J : I { |
| 76 |
int *a; |
| 77 |
int *b; |
| 78 |
int c; |
| 79 |
J() : I((a = new int(5))), b(a), c(*a) { } |
| 80 |
}; |
| 81 |
|
| 82 |
struct M { }; |
| 83 |
|
| 84 |
struct N : public M { |
| 85 |
int a; |
| 86 |
int b; |
| 87 |
N() : b(a) { } // { dg-warning "member .N::a. is used uninitialized" } |
| 88 |
}; |
| 89 |
|
| 90 |
struct O { |
| 91 |
int x = 42; |
| 92 |
int get() { return x; } |
| 93 |
}; |
| 94 |
|
| 95 |
struct P { |
| 96 |
O o; |
| 97 |
int x = o.get(); |
| 98 |
P() : x(o.get()) { } |
| 99 |
}; |
| 100 |
|
| 101 |
struct Q { |
| 102 |
int a; |
| 103 |
int b; |
| 104 |
int &c; |
| 105 |
Q() : |
| 106 |
a(c = 5), // "reference .Q::c. is not yet bound" but too complex for the FE |
| 107 |
b(c), // "reference .Q::c. is not yet bound" but too complex for the FE |
| 108 |
c(a) { } |
| 109 |
}; |
| 110 |
|
| 111 |
struct R { |
| 112 |
int a; |
| 113 |
int b; |
| 114 |
int c; |
| 115 |
int d = a + b + c; |
| 116 |
R() : a(c = 5), b(c), c(a) { } |
| 117 |
}; |