1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wall -Wuninitialized -Wno-unused-value -std=c++11 -verify %s
2f4a2713aSLionel Sambuc
3*0a6a1f1dSLionel Sambuc // definitions for std::move
4*0a6a1f1dSLionel Sambuc namespace std {
5*0a6a1f1dSLionel Sambuc inline namespace foo {
6*0a6a1f1dSLionel Sambuc template <class T> struct remove_reference { typedef T type; };
7*0a6a1f1dSLionel Sambuc template <class T> struct remove_reference<T&> { typedef T type; };
8*0a6a1f1dSLionel Sambuc template <class T> struct remove_reference<T&&> { typedef T type; };
9*0a6a1f1dSLionel Sambuc
10*0a6a1f1dSLionel Sambuc template <class T> typename remove_reference<T>::type&& move(T&& t);
11*0a6a1f1dSLionel Sambuc }
12*0a6a1f1dSLionel Sambuc }
13*0a6a1f1dSLionel Sambuc
14f4a2713aSLionel Sambuc int foo(int x);
15f4a2713aSLionel Sambuc int bar(int* x);
16f4a2713aSLionel Sambuc int boo(int& x);
17f4a2713aSLionel Sambuc int far(const int& x);
18*0a6a1f1dSLionel Sambuc int moved(int&& x);
19*0a6a1f1dSLionel Sambuc int &ref(int x);
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc // Test self-references within initializers which are guaranteed to be
22f4a2713aSLionel Sambuc // uninitialized.
23f4a2713aSLionel Sambuc int a = a; // no-warning: used to signal intended lack of initialization.
24f4a2713aSLionel Sambuc int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
25f4a2713aSLionel Sambuc int c = (c + c); // expected-warning 2 {{variable 'c' is uninitialized when used within its own initialization}}
26f4a2713aSLionel Sambuc int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
27f4a2713aSLionel Sambuc int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
28f4a2713aSLionel Sambuc
29f4a2713aSLionel Sambuc // Thes don't warn as they don't require the value.
30f4a2713aSLionel Sambuc int g = sizeof(g);
31f4a2713aSLionel Sambuc void* ptr = &ptr;
32f4a2713aSLionel Sambuc int h = bar(&h);
33f4a2713aSLionel Sambuc int i = boo(i);
34f4a2713aSLionel Sambuc int j = far(j);
35f4a2713aSLionel Sambuc int k = __alignof__(k);
36f4a2713aSLionel Sambuc
37f4a2713aSLionel Sambuc int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}}
38f4a2713aSLionel Sambuc int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}}
39f4a2713aSLionel Sambuc int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
40*0a6a1f1dSLionel Sambuc int o = std::move(o); // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
41*0a6a1f1dSLionel Sambuc const int p = std::move(p); // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
42*0a6a1f1dSLionel Sambuc int q = moved(std::move(q)); // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
43*0a6a1f1dSLionel Sambuc int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
44*0a6a1f1dSLionel Sambuc int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
45*0a6a1f1dSLionel Sambuc int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
46*0a6a1f1dSLionel Sambuc int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
47*0a6a1f1dSLionel Sambuc int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
48*0a6a1f1dSLionel Sambuc int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
49*0a6a1f1dSLionel Sambuc int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
50*0a6a1f1dSLionel Sambuc int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
51*0a6a1f1dSLionel Sambuc int z = ++ref(z); // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
52*0a6a1f1dSLionel Sambuc int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
53*0a6a1f1dSLionel Sambuc int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
54f4a2713aSLionel Sambuc
test_stuff()55f4a2713aSLionel Sambuc void test_stuff () {
56f4a2713aSLionel Sambuc int a = a; // no-warning: used to signal intended lack of initialization.
57f4a2713aSLionel Sambuc int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
58f4a2713aSLionel Sambuc int c = (c + c); // expected-warning {{variable 'c' is uninitialized when used within its own initialization}}
59f4a2713aSLionel Sambuc int d = ({ d + d ;}); // expected-warning {{variable 'd' is uninitialized when used within its own initialization}}
60f4a2713aSLionel Sambuc int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
61f4a2713aSLionel Sambuc int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
62f4a2713aSLionel Sambuc
63f4a2713aSLionel Sambuc // Thes don't warn as they don't require the value.
64f4a2713aSLionel Sambuc int g = sizeof(g);
65f4a2713aSLionel Sambuc void* ptr = &ptr;
66f4a2713aSLionel Sambuc int h = bar(&h);
67f4a2713aSLionel Sambuc int i = boo(i);
68f4a2713aSLionel Sambuc int j = far(j);
69f4a2713aSLionel Sambuc int k = __alignof__(k);
70f4a2713aSLionel Sambuc
71f4a2713aSLionel Sambuc int l = k ? l : l; // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
72f4a2713aSLionel Sambuc int m = 1 + (k ? m : m); // expected-warning {{'m' is uninitialized when used within its own initialization}}
73f4a2713aSLionel Sambuc int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
74*0a6a1f1dSLionel Sambuc int o = std::move(o); // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
75*0a6a1f1dSLionel Sambuc const int p = std::move(p); // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
76*0a6a1f1dSLionel Sambuc int q = moved(std::move(q)); // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
77*0a6a1f1dSLionel Sambuc int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
78*0a6a1f1dSLionel Sambuc int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
79*0a6a1f1dSLionel Sambuc int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
80*0a6a1f1dSLionel Sambuc int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
81*0a6a1f1dSLionel Sambuc int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
82*0a6a1f1dSLionel Sambuc int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
83*0a6a1f1dSLionel Sambuc int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
84*0a6a1f1dSLionel Sambuc int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
85*0a6a1f1dSLionel Sambuc int z = ++ref(z); // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
86*0a6a1f1dSLionel Sambuc int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
87*0a6a1f1dSLionel Sambuc int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
88*0a6a1f1dSLionel Sambuc
89f4a2713aSLionel Sambuc
90f4a2713aSLionel Sambuc for (;;) {
91f4a2713aSLionel Sambuc int a = a; // no-warning: used to signal intended lack of initialization.
92f4a2713aSLionel Sambuc int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
93f4a2713aSLionel Sambuc int c = (c + c); // expected-warning {{variable 'c' is uninitialized when used within its own initialization}}
94f4a2713aSLionel Sambuc int d = ({ d + d ;}); // expected-warning {{variable 'd' is uninitialized when used within its own initialization}}
95f4a2713aSLionel Sambuc int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
96f4a2713aSLionel Sambuc int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
97f4a2713aSLionel Sambuc
98f4a2713aSLionel Sambuc // Thes don't warn as they don't require the value.
99f4a2713aSLionel Sambuc int g = sizeof(g);
100f4a2713aSLionel Sambuc void* ptr = &ptr;
101f4a2713aSLionel Sambuc int h = bar(&h);
102f4a2713aSLionel Sambuc int i = boo(i);
103f4a2713aSLionel Sambuc int j = far(j);
104f4a2713aSLionel Sambuc int k = __alignof__(k);
105f4a2713aSLionel Sambuc
106f4a2713aSLionel Sambuc int l = k ? l : l; // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
107f4a2713aSLionel Sambuc int m = 1 + (k ? m : m); // expected-warning {{'m' is uninitialized when used within its own initialization}}
108f4a2713aSLionel Sambuc int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
109*0a6a1f1dSLionel Sambuc int o = std::move(o); // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
110*0a6a1f1dSLionel Sambuc const int p = std::move(p); // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
111*0a6a1f1dSLionel Sambuc int q = moved(std::move(q)); // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
112*0a6a1f1dSLionel Sambuc int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
113*0a6a1f1dSLionel Sambuc int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
114*0a6a1f1dSLionel Sambuc int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
115*0a6a1f1dSLionel Sambuc int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
116*0a6a1f1dSLionel Sambuc int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
117*0a6a1f1dSLionel Sambuc int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
118*0a6a1f1dSLionel Sambuc int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
119*0a6a1f1dSLionel Sambuc int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
120*0a6a1f1dSLionel Sambuc int z = ++ref(z); // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
121*0a6a1f1dSLionel Sambuc int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
122*0a6a1f1dSLionel Sambuc int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
123*0a6a1f1dSLionel Sambuc
124f4a2713aSLionel Sambuc }
125f4a2713aSLionel Sambuc }
126f4a2713aSLionel Sambuc
127*0a6a1f1dSLionel Sambuc // Also test similar constructs in a field's initializer.
128*0a6a1f1dSLionel Sambuc struct S {
129*0a6a1f1dSLionel Sambuc int x;
130*0a6a1f1dSLionel Sambuc int y;
131*0a6a1f1dSLionel Sambuc const int z = 5;
132*0a6a1f1dSLionel Sambuc void *ptr;
133*0a6a1f1dSLionel Sambuc
SS134*0a6a1f1dSLionel Sambuc S(bool (*)[1]) : x(x) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS135*0a6a1f1dSLionel Sambuc S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS136*0a6a1f1dSLionel Sambuc S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field 'x' is uninitialized when used here}}
SS137*0a6a1f1dSLionel Sambuc S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS138*0a6a1f1dSLionel Sambuc S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field 'x' is uninitialized when used here}}
139*0a6a1f1dSLionel Sambuc
140*0a6a1f1dSLionel Sambuc // These don't actually require the value of x and so shouldn't warn.
SS141*0a6a1f1dSLionel Sambuc S(char (*)[1]) : x(sizeof(x)) {} // rdar://8610363
SS142*0a6a1f1dSLionel Sambuc S(char (*)[2]) : ptr(&ptr) {}
SS143*0a6a1f1dSLionel Sambuc S(char (*)[3]) : x(bar(&x)) {}
SS144*0a6a1f1dSLionel Sambuc S(char (*)[4]) : x(boo(x)) {}
SS145*0a6a1f1dSLionel Sambuc S(char (*)[5]) : x(far(x)) {}
SS146*0a6a1f1dSLionel Sambuc S(char (*)[6]) : x(__alignof__(x)) {}
147*0a6a1f1dSLionel Sambuc
SS148*0a6a1f1dSLionel Sambuc S(int (*)[1]) : x(0), y(x ? y : y) {} // expected-warning 2{{field 'y' is uninitialized when used here}}
SS149*0a6a1f1dSLionel Sambuc S(int (*)[2]) : x(0), y(1 + (x ? y : y)) {} // expected-warning 2{{field 'y' is uninitialized when used here}}
SS150*0a6a1f1dSLionel Sambuc S(int (*)[3]) : x(-x) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS151*0a6a1f1dSLionel Sambuc S(int (*)[4]) : x(std::move(x)) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS152*0a6a1f1dSLionel Sambuc S(int (*)[5]) : z(std::move(z)) {} // expected-warning {{field 'z' is uninitialized when used here}}
SS153*0a6a1f1dSLionel Sambuc S(int (*)[6]) : x(moved(std::move(x))) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS154*0a6a1f1dSLionel Sambuc S(int (*)[7]) : x(0), y(std::move((x ? x : (18, y)))) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS155*0a6a1f1dSLionel Sambuc S(int (*)[8]) : x(0), y(x ?: y) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS156*0a6a1f1dSLionel Sambuc S(int (*)[9]) : x(0), y(y ?: x) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS157*0a6a1f1dSLionel Sambuc S(int (*)[10]) : x(0), y((foo(y), x)) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS158*0a6a1f1dSLionel Sambuc S(int (*)[11]) : x(0), y(x += y) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS159*0a6a1f1dSLionel Sambuc S(int (*)[12]) : x(x += 10) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS160*0a6a1f1dSLionel Sambuc S(int (*)[13]) : x(x++) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS161*0a6a1f1dSLionel Sambuc S(int (*)[14]) : x(0), y(((x ? (y, x) : (77, y))++, sizeof(y))) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS162*0a6a1f1dSLionel Sambuc S(int (*)[15]) : x(++ref(x)) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS163*0a6a1f1dSLionel Sambuc S(int (*)[16]) : x((ref(x) += 10)) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS164*0a6a1f1dSLionel Sambuc S(int (*)[17]) : x(0), y(y ? x : x) {} // expected-warning {{field 'y' is uninitialized when used here}}
165*0a6a1f1dSLionel Sambuc };
166*0a6a1f1dSLionel Sambuc
167f4a2713aSLionel Sambuc // Test self-references with record types.
168f4a2713aSLionel Sambuc class A {
169f4a2713aSLionel Sambuc // Non-POD class.
170f4a2713aSLionel Sambuc public:
171f4a2713aSLionel Sambuc enum count { ONE, TWO, THREE };
172f4a2713aSLionel Sambuc int num;
173f4a2713aSLionel Sambuc static int count;
get() const174f4a2713aSLionel Sambuc int get() const { return num; }
get2()175f4a2713aSLionel Sambuc int get2() { return num; }
set(int x)176*0a6a1f1dSLionel Sambuc int set(int x) { num = x; return num; }
zero()177f4a2713aSLionel Sambuc static int zero() { return 0; }
178f4a2713aSLionel Sambuc
A()179f4a2713aSLionel Sambuc A() {}
A(A const & a)180f4a2713aSLionel Sambuc A(A const &a) {}
A(int x)181f4a2713aSLionel Sambuc A(int x) {}
A(int * x)182f4a2713aSLionel Sambuc A(int *x) {}
A(A * a)183f4a2713aSLionel Sambuc A(A *a) {}
A(A && a)184*0a6a1f1dSLionel Sambuc A(A &&a) {}
185f4a2713aSLionel Sambuc ~A();
186*0a6a1f1dSLionel Sambuc bool operator!();
187*0a6a1f1dSLionel Sambuc bool operator!=(const A&);
188f4a2713aSLionel Sambuc };
189f4a2713aSLionel Sambuc
190*0a6a1f1dSLionel Sambuc bool operator!=(int, const A&);
191*0a6a1f1dSLionel Sambuc
getA()192f4a2713aSLionel Sambuc A getA() { return A(); }
getA(int x)193f4a2713aSLionel Sambuc A getA(int x) { return A(); }
getA(A * a)194f4a2713aSLionel Sambuc A getA(A* a) { return A(); }
getA(A a)195f4a2713aSLionel Sambuc A getA(A a) { return A(); }
moveA(A && a)196*0a6a1f1dSLionel Sambuc A moveA(A&& a) { return A(); }
const_refA(const A & a)197*0a6a1f1dSLionel Sambuc A const_refA(const A& a) { return A(); }
198f4a2713aSLionel Sambuc
setupA(bool x)199f4a2713aSLionel Sambuc void setupA(bool x) {
200f4a2713aSLionel Sambuc A a1;
201f4a2713aSLionel Sambuc a1.set(a1.get());
202f4a2713aSLionel Sambuc A a2(a1.get());
203f4a2713aSLionel Sambuc A a3(a1);
204f4a2713aSLionel Sambuc A a4(&a4);
205f4a2713aSLionel Sambuc A a5(a5.zero());
206f4a2713aSLionel Sambuc A a6(a6.ONE);
207f4a2713aSLionel Sambuc A a7 = getA();
208f4a2713aSLionel Sambuc A a8 = getA(a8.TWO);
209f4a2713aSLionel Sambuc A a9 = getA(&a9);
210f4a2713aSLionel Sambuc A a10(a10.count);
211f4a2713aSLionel Sambuc
212f4a2713aSLionel Sambuc A a11(a11); // expected-warning {{variable 'a11' is uninitialized when used within its own initialization}}
213f4a2713aSLionel Sambuc A a12(a12.get()); // expected-warning {{variable 'a12' is uninitialized when used within its own initialization}}
214f4a2713aSLionel Sambuc A a13(a13.num); // expected-warning {{variable 'a13' is uninitialized when used within its own initialization}}
215f4a2713aSLionel Sambuc A a14 = A(a14); // expected-warning {{variable 'a14' is uninitialized when used within its own initialization}}
216f4a2713aSLionel Sambuc A a15 = getA(a15.num); // expected-warning {{variable 'a15' is uninitialized when used within its own initialization}}
217f4a2713aSLionel Sambuc A a16(&a16.num); // expected-warning {{variable 'a16' is uninitialized when used within its own initialization}}
218f4a2713aSLionel Sambuc A a17(a17.get2()); // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}}
219f4a2713aSLionel Sambuc A a18 = x ? a18 : a17; // expected-warning {{variable 'a18' is uninitialized when used within its own initialization}}
220f4a2713aSLionel Sambuc A a19 = getA(x ? a19 : a17); // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}}
221f4a2713aSLionel Sambuc A a20{a20}; // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}}
222f4a2713aSLionel Sambuc A a21 = {a21}; // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}}
223f4a2713aSLionel Sambuc
224*0a6a1f1dSLionel Sambuc // FIXME: Make the local uninitialized warning consistent with the global
225f4a2713aSLionel Sambuc // uninitialized checking.
226f4a2713aSLionel Sambuc A *a22 = new A(a22->count); // expected-warning {{variable 'a22' is uninitialized when used within its own initialization}}
227f4a2713aSLionel Sambuc A *a23 = new A(a23->ONE); // expected-warning {{variable 'a23' is uninitialized when used within its own initialization}}
228f4a2713aSLionel Sambuc A *a24 = new A(a24->TWO); // expected-warning {{variable 'a24' is uninitialized when used within its own initialization}}
229f4a2713aSLionel Sambuc A *a25 = new A(a25->zero()); // expected-warning {{variable 'a25' is uninitialized when used within its own initialization}}
230f4a2713aSLionel Sambuc
231f4a2713aSLionel Sambuc A *a26 = new A(a26->get()); // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}}
232f4a2713aSLionel Sambuc A *a27 = new A(a27->get2()); // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}}
233f4a2713aSLionel Sambuc A *a28 = new A(a28->num); // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}}
234*0a6a1f1dSLionel Sambuc
235*0a6a1f1dSLionel Sambuc const A a29(a29); // expected-warning {{variable 'a29' is uninitialized when used within its own initialization}}
236*0a6a1f1dSLionel Sambuc const A a30 = a30; // expected-warning {{variable 'a30' is uninitialized when used within its own initialization}}
237*0a6a1f1dSLionel Sambuc
238*0a6a1f1dSLionel Sambuc A a31 = std::move(a31); // expected-warning {{variable 'a31' is uninitialized when used within its own initialization}}
239*0a6a1f1dSLionel Sambuc A a32 = moveA(std::move(a32)); // expected-warning {{variable 'a32' is uninitialized when used within its own initialization}}
240*0a6a1f1dSLionel Sambuc A a33 = A(std::move(a33)); // expected-warning {{variable 'a33' is uninitialized when used within its own initialization}}
241*0a6a1f1dSLionel Sambuc A a34(std::move(a34)); // expected-warning {{variable 'a34' is uninitialized when used within its own initialization}}
242*0a6a1f1dSLionel Sambuc A a35 = std::move(x ? a34 : (37, a35)); // expected-warning {{variable 'a35' is uninitialized when used within its own initialization}}
243*0a6a1f1dSLionel Sambuc
244*0a6a1f1dSLionel Sambuc A a36 = const_refA(a36);
245*0a6a1f1dSLionel Sambuc A a37(const_refA(a37));
246*0a6a1f1dSLionel Sambuc
247*0a6a1f1dSLionel Sambuc A a38({a38}); // expected-warning {{variable 'a38' is uninitialized when used within its own initialization}}
248*0a6a1f1dSLionel Sambuc A a39 = {a39}; // expected-warning {{variable 'a39' is uninitialized when used within its own initialization}}
249*0a6a1f1dSLionel Sambuc A a40 = A({a40}); // expected-warning {{variable 'a40' is uninitialized when used within its own initialization}}
250*0a6a1f1dSLionel Sambuc
251*0a6a1f1dSLionel Sambuc A a41 = !a41; // expected-warning {{variable 'a41' is uninitialized when used within its own initialization}}
252*0a6a1f1dSLionel Sambuc A a42 = !(a42); // expected-warning {{variable 'a42' is uninitialized when used within its own initialization}}
253*0a6a1f1dSLionel Sambuc A a43 = a43 != a42; // expected-warning {{variable 'a43' is uninitialized when used within its own initialization}}
254*0a6a1f1dSLionel Sambuc A a44 = a43 != a44; // expected-warning {{variable 'a44' is uninitialized when used within its own initialization}}
255*0a6a1f1dSLionel Sambuc A a45 = a45 != a45; // expected-warning 2{{variable 'a45' is uninitialized when used within its own initialization}}
256*0a6a1f1dSLionel Sambuc A a46 = 0 != a46; // expected-warning {{variable 'a46' is uninitialized when used within its own initialization}}
257*0a6a1f1dSLionel Sambuc
258*0a6a1f1dSLionel Sambuc A a47(a47.set(a47.num)); // expected-warning 2{{variable 'a47' is uninitialized when used within its own initialization}}
259*0a6a1f1dSLionel Sambuc A a48(a47.set(a48.num)); // expected-warning {{variable 'a48' is uninitialized when used within its own initialization}}
260*0a6a1f1dSLionel Sambuc A a49(a47.set(a48.num));
261f4a2713aSLionel Sambuc }
262f4a2713aSLionel Sambuc
263*0a6a1f1dSLionel Sambuc bool cond;
264f4a2713aSLionel Sambuc
265f4a2713aSLionel Sambuc A a1;
266f4a2713aSLionel Sambuc A a2(a1.get());
267f4a2713aSLionel Sambuc A a3(a1);
268f4a2713aSLionel Sambuc A a4(&a4);
269f4a2713aSLionel Sambuc A a5(a5.zero());
270f4a2713aSLionel Sambuc A a6(a6.ONE);
271f4a2713aSLionel Sambuc A a7 = getA();
272f4a2713aSLionel Sambuc A a8 = getA(a8.TWO);
273f4a2713aSLionel Sambuc A a9 = getA(&a9);
274f4a2713aSLionel Sambuc A a10(a10.count);
275f4a2713aSLionel Sambuc
276f4a2713aSLionel Sambuc A a11(a11); // expected-warning {{variable 'a11' is uninitialized when used within its own initialization}}
277f4a2713aSLionel Sambuc A a12(a12.get()); // expected-warning {{variable 'a12' is uninitialized when used within its own initialization}}
278f4a2713aSLionel Sambuc A a13(a13.num); // expected-warning {{variable 'a13' is uninitialized when used within its own initialization}}
279f4a2713aSLionel Sambuc A a14 = A(a14); // expected-warning {{variable 'a14' is uninitialized when used within its own initialization}}
280f4a2713aSLionel Sambuc A a15 = getA(a15.num); // expected-warning {{variable 'a15' is uninitialized when used within its own initialization}}
281f4a2713aSLionel Sambuc A a16(&a16.num); // expected-warning {{variable 'a16' is uninitialized when used within its own initialization}}
282f4a2713aSLionel Sambuc A a17(a17.get2()); // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}}
283*0a6a1f1dSLionel Sambuc A a18 = cond ? a18 : a17; // expected-warning {{variable 'a18' is uninitialized when used within its own initialization}}
284*0a6a1f1dSLionel Sambuc A a19 = getA(cond ? a19 : a17); // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}}
285f4a2713aSLionel Sambuc A a20{a20}; // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}}
286f4a2713aSLionel Sambuc A a21 = {a21}; // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}}
287f4a2713aSLionel Sambuc
288f4a2713aSLionel Sambuc A *a22 = new A(a22->count);
289f4a2713aSLionel Sambuc A *a23 = new A(a23->ONE);
290f4a2713aSLionel Sambuc A *a24 = new A(a24->TWO);
291f4a2713aSLionel Sambuc A *a25 = new A(a25->zero());
292f4a2713aSLionel Sambuc
293f4a2713aSLionel Sambuc A *a26 = new A(a26->get()); // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}}
294f4a2713aSLionel Sambuc A *a27 = new A(a27->get2()); // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}}
295f4a2713aSLionel Sambuc A *a28 = new A(a28->num); // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}}
296f4a2713aSLionel Sambuc
297*0a6a1f1dSLionel Sambuc const A a29(a29); // expected-warning {{variable 'a29' is uninitialized when used within its own initialization}}
298*0a6a1f1dSLionel Sambuc const A a30 = a30; // expected-warning {{variable 'a30' is uninitialized when used within its own initialization}}
299*0a6a1f1dSLionel Sambuc
300*0a6a1f1dSLionel Sambuc A a31 = std::move(a31); // expected-warning {{variable 'a31' is uninitialized when used within its own initialization}}
301*0a6a1f1dSLionel Sambuc A a32 = moveA(std::move(a32)); // expected-warning {{variable 'a32' is uninitialized when used within its own initialization}}
302*0a6a1f1dSLionel Sambuc A a33 = A(std::move(a33)); // expected-warning {{variable 'a33' is uninitialized when used within its own initialization}}
303*0a6a1f1dSLionel Sambuc A a34(std::move(a34)); // expected-warning {{variable 'a34' is uninitialized when used within its own initialization}}
304*0a6a1f1dSLionel Sambuc A a35 = std::move(x ? a34 : (37, a35)); // expected-warning {{variable 'a35' is uninitialized when used within its own initialization}}
305*0a6a1f1dSLionel Sambuc
306*0a6a1f1dSLionel Sambuc A a36 = const_refA(a36);
307*0a6a1f1dSLionel Sambuc A a37(const_refA(a37));
308*0a6a1f1dSLionel Sambuc
309*0a6a1f1dSLionel Sambuc A a38({a38}); // expected-warning {{variable 'a38' is uninitialized when used within its own initialization}}
310*0a6a1f1dSLionel Sambuc A a39 = {a39}; // expected-warning {{variable 'a39' is uninitialized when used within its own initialization}}
311*0a6a1f1dSLionel Sambuc A a40 = A({a40}); // expected-warning {{variable 'a40' is uninitialized when used within its own initialization}}
312*0a6a1f1dSLionel Sambuc
313*0a6a1f1dSLionel Sambuc A a41 = !a41; // expected-warning {{variable 'a41' is uninitialized when used within its own initialization}}
314*0a6a1f1dSLionel Sambuc A a42 = !(a42); // expected-warning {{variable 'a42' is uninitialized when used within its own initialization}}
315*0a6a1f1dSLionel Sambuc A a43 = a43 != a42; // expected-warning {{variable 'a43' is uninitialized when used within its own initialization}}
316*0a6a1f1dSLionel Sambuc A a44 = a43 != a44; // expected-warning {{variable 'a44' is uninitialized when used within its own initialization}}
317*0a6a1f1dSLionel Sambuc A a45 = a45 != a45; // expected-warning 2{{variable 'a45' is uninitialized when used within its own initialization}}
318*0a6a1f1dSLionel Sambuc
319*0a6a1f1dSLionel Sambuc A a46 = 0 != a46; // expected-warning {{variable 'a46' is uninitialized when used within its own initialization}}
320*0a6a1f1dSLionel Sambuc
321*0a6a1f1dSLionel Sambuc A a47(a47.set(a47.num)); // expected-warning 2{{variable 'a47' is uninitialized when used within its own initialization}}
322*0a6a1f1dSLionel Sambuc A a48(a47.set(a48.num)); // expected-warning {{variable 'a48' is uninitialized when used within its own initialization}}
323*0a6a1f1dSLionel Sambuc A a49(a47.set(a48.num));
324*0a6a1f1dSLionel Sambuc
325*0a6a1f1dSLionel Sambuc class T {
326*0a6a1f1dSLionel Sambuc A a, a2;
327*0a6a1f1dSLionel Sambuc const A c_a;
328*0a6a1f1dSLionel Sambuc A* ptr_a;
329*0a6a1f1dSLionel Sambuc
T()330*0a6a1f1dSLionel Sambuc T() {}
T(bool (*)[1])331*0a6a1f1dSLionel Sambuc T(bool (*)[1]) : a() {}
T(bool (*)[2])332*0a6a1f1dSLionel Sambuc T(bool (*)[2]) : a2(a.get()) {}
T(bool (*)[3])333*0a6a1f1dSLionel Sambuc T(bool (*)[3]) : a2(a) {}
T(bool (*)[4])334*0a6a1f1dSLionel Sambuc T(bool (*)[4]) : a(&a) {}
T(bool (*)[5])335*0a6a1f1dSLionel Sambuc T(bool (*)[5]) : a(a.zero()) {}
T(bool (*)[6])336*0a6a1f1dSLionel Sambuc T(bool (*)[6]) : a(a.ONE) {}
T(bool (*)[7])337*0a6a1f1dSLionel Sambuc T(bool (*)[7]) : a(getA()) {}
T(bool (*)[8])338*0a6a1f1dSLionel Sambuc T(bool (*)[8]) : a2(getA(a.TWO)) {}
T(bool (*)[9])339*0a6a1f1dSLionel Sambuc T(bool (*)[9]) : a(getA(&a)) {}
T(bool (*)[10])340*0a6a1f1dSLionel Sambuc T(bool (*)[10]) : a(a.count) {}
341*0a6a1f1dSLionel Sambuc
T(bool (*)[11])342*0a6a1f1dSLionel Sambuc T(bool (*)[11]) : a(a) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[12])343*0a6a1f1dSLionel Sambuc T(bool (*)[12]) : a(a.get()) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[13])344*0a6a1f1dSLionel Sambuc T(bool (*)[13]) : a(a.num) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[14])345*0a6a1f1dSLionel Sambuc T(bool (*)[14]) : a(A(a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[15])346*0a6a1f1dSLionel Sambuc T(bool (*)[15]) : a(getA(a.num)) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[16])347*0a6a1f1dSLionel Sambuc T(bool (*)[16]) : a(&a.num) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[17])348*0a6a1f1dSLionel Sambuc T(bool (*)[17]) : a(a.get2()) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[18])349*0a6a1f1dSLionel Sambuc T(bool (*)[18]) : a2(cond ? a2 : a) {} // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[19])350*0a6a1f1dSLionel Sambuc T(bool (*)[19]) : a2(cond ? a2 : a) {} // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[20])351*0a6a1f1dSLionel Sambuc T(bool (*)[20]) : a{a} {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[21])352*0a6a1f1dSLionel Sambuc T(bool (*)[21]) : a({a}) {} // expected-warning {{field 'a' is uninitialized when used here}}
353*0a6a1f1dSLionel Sambuc
T(bool (*)[22])354*0a6a1f1dSLionel Sambuc T(bool (*)[22]) : ptr_a(new A(ptr_a->count)) {}
T(bool (*)[23])355*0a6a1f1dSLionel Sambuc T(bool (*)[23]) : ptr_a(new A(ptr_a->ONE)) {}
T(bool (*)[24])356*0a6a1f1dSLionel Sambuc T(bool (*)[24]) : ptr_a(new A(ptr_a->TWO)) {}
T(bool (*)[25])357*0a6a1f1dSLionel Sambuc T(bool (*)[25]) : ptr_a(new A(ptr_a->zero())) {}
358*0a6a1f1dSLionel Sambuc
T(bool (*)[26])359*0a6a1f1dSLionel Sambuc T(bool (*)[26]) : ptr_a(new A(ptr_a->get())) {} // expected-warning {{field 'ptr_a' is uninitialized when used here}}
T(bool (*)[27])360*0a6a1f1dSLionel Sambuc T(bool (*)[27]) : ptr_a(new A(ptr_a->get2())) {} // expected-warning {{field 'ptr_a' is uninitialized when used here}}
T(bool (*)[28])361*0a6a1f1dSLionel Sambuc T(bool (*)[28]) : ptr_a(new A(ptr_a->num)) {} // expected-warning {{field 'ptr_a' is uninitialized when used here}}
362*0a6a1f1dSLionel Sambuc
T(bool (*)[29])363*0a6a1f1dSLionel Sambuc T(bool (*)[29]) : c_a(c_a) {} // expected-warning {{field 'c_a' is uninitialized when used here}}
T(bool (*)[30])364*0a6a1f1dSLionel Sambuc T(bool (*)[30]) : c_a(A(c_a)) {} // expected-warning {{field 'c_a' is uninitialized when used here}}
365*0a6a1f1dSLionel Sambuc
T(bool (*)[31])366*0a6a1f1dSLionel Sambuc T(bool (*)[31]) : a(std::move(a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[32])367*0a6a1f1dSLionel Sambuc T(bool (*)[32]) : a(moveA(std::move(a))) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[33])368*0a6a1f1dSLionel Sambuc T(bool (*)[33]) : a(A(std::move(a))) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[34])369*0a6a1f1dSLionel Sambuc T(bool (*)[34]) : a(A(std::move(a))) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[35])370*0a6a1f1dSLionel Sambuc T(bool (*)[35]) : a2(std::move(x ? a : (37, a2))) {} // expected-warning {{field 'a2' is uninitialized when used here}}
371*0a6a1f1dSLionel Sambuc
T(bool (*)[36])372*0a6a1f1dSLionel Sambuc T(bool (*)[36]) : a(const_refA(a)) {}
T(bool (*)[37])373*0a6a1f1dSLionel Sambuc T(bool (*)[37]) : a(A(const_refA(a))) {}
374*0a6a1f1dSLionel Sambuc
T(bool (*)[38])375*0a6a1f1dSLionel Sambuc T(bool (*)[38]) : a({a}) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[39])376*0a6a1f1dSLionel Sambuc T(bool (*)[39]) : a{a} {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[40])377*0a6a1f1dSLionel Sambuc T(bool (*)[40]) : a({a}) {} // expected-warning {{field 'a' is uninitialized when used here}}
378*0a6a1f1dSLionel Sambuc
T(bool (*)[41])379*0a6a1f1dSLionel Sambuc T(bool (*)[41]) : a(!a) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[42])380*0a6a1f1dSLionel Sambuc T(bool (*)[42]) : a(!(a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[43])381*0a6a1f1dSLionel Sambuc T(bool (*)[43]) : a(), a2(a2 != a) {} // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[44])382*0a6a1f1dSLionel Sambuc T(bool (*)[44]) : a(), a2(a != a2) {} // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[45])383*0a6a1f1dSLionel Sambuc T(bool (*)[45]) : a(a != a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
T(bool (*)[46])384*0a6a1f1dSLionel Sambuc T(bool (*)[46]) : a(0 != a) {} // expected-warning {{field 'a' is uninitialized when used here}}
385*0a6a1f1dSLionel Sambuc
T(bool (*)[47])386*0a6a1f1dSLionel Sambuc T(bool (*)[47]) : a2(a2.set(a2.num)) {} // expected-warning 2{{field 'a2' is uninitialized when used here}}
T(bool (*)[48])387*0a6a1f1dSLionel Sambuc T(bool (*)[48]) : a2(a.set(a2.num)) {} // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[49])388*0a6a1f1dSLionel Sambuc T(bool (*)[49]) : a2(a.set(a.num)) {}
389*0a6a1f1dSLionel Sambuc
390*0a6a1f1dSLionel Sambuc };
391*0a6a1f1dSLionel Sambuc
392f4a2713aSLionel Sambuc struct B {
393f4a2713aSLionel Sambuc // POD struct.
394f4a2713aSLionel Sambuc int x;
395f4a2713aSLionel Sambuc int *y;
396f4a2713aSLionel Sambuc };
397f4a2713aSLionel Sambuc
getB()398f4a2713aSLionel Sambuc B getB() { return B(); };
getB(int x)399f4a2713aSLionel Sambuc B getB(int x) { return B(); };
getB(int * x)400f4a2713aSLionel Sambuc B getB(int *x) { return B(); };
getB(B * b)401f4a2713aSLionel Sambuc B getB(B *b) { return B(); };
moveB(B && b)402*0a6a1f1dSLionel Sambuc B moveB(B &&b) { return B(); };
403f4a2713aSLionel Sambuc
getPtrB()404f4a2713aSLionel Sambuc B* getPtrB() { return 0; };
getPtrB(int x)405f4a2713aSLionel Sambuc B* getPtrB(int x) { return 0; };
getPtrB(int * x)406f4a2713aSLionel Sambuc B* getPtrB(int *x) { return 0; };
getPtrB(B ** b)407f4a2713aSLionel Sambuc B* getPtrB(B **b) { return 0; };
408f4a2713aSLionel Sambuc
setupB(bool x)409*0a6a1f1dSLionel Sambuc void setupB(bool x) {
410f4a2713aSLionel Sambuc B b1;
411f4a2713aSLionel Sambuc B b2(b1);
412f4a2713aSLionel Sambuc B b3 = { 5, &b3.x };
413f4a2713aSLionel Sambuc B b4 = getB();
414f4a2713aSLionel Sambuc B b5 = getB(&b5);
415f4a2713aSLionel Sambuc B b6 = getB(&b6.x);
416f4a2713aSLionel Sambuc
417f4a2713aSLionel Sambuc // Silence unused warning
418f4a2713aSLionel Sambuc (void) b2;
419f4a2713aSLionel Sambuc (void) b4;
420f4a2713aSLionel Sambuc
421f4a2713aSLionel Sambuc B b7(b7); // expected-warning {{variable 'b7' is uninitialized when used within its own initialization}}
422f4a2713aSLionel Sambuc B b8 = getB(b8.x); // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}}
423f4a2713aSLionel Sambuc B b9 = getB(b9.y); // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}}
424f4a2713aSLionel Sambuc B b10 = getB(-b10.x); // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}}
425f4a2713aSLionel Sambuc
426f4a2713aSLionel Sambuc B* b11 = 0;
427f4a2713aSLionel Sambuc B* b12(b11);
428f4a2713aSLionel Sambuc B* b13 = getPtrB();
429f4a2713aSLionel Sambuc B* b14 = getPtrB(&b14);
430f4a2713aSLionel Sambuc
431f4a2713aSLionel Sambuc (void) b12;
432f4a2713aSLionel Sambuc (void) b13;
433f4a2713aSLionel Sambuc
434f4a2713aSLionel Sambuc B* b15 = getPtrB(b15->x); // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}}
435f4a2713aSLionel Sambuc B* b16 = getPtrB(b16->y); // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}}
436f4a2713aSLionel Sambuc
437f4a2713aSLionel Sambuc B b17 = { b17.x = 5, b17.y = 0 };
438f4a2713aSLionel Sambuc B b18 = { b18.x + 1, b18.y }; // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}}
439*0a6a1f1dSLionel Sambuc
440*0a6a1f1dSLionel Sambuc const B b19 = b19; // expected-warning {{variable 'b19' is uninitialized when used within its own initialization}}
441*0a6a1f1dSLionel Sambuc const B b20(b20); // expected-warning {{variable 'b20' is uninitialized when used within its own initialization}}
442*0a6a1f1dSLionel Sambuc
443*0a6a1f1dSLionel Sambuc B b21 = std::move(b21); // expected-warning {{variable 'b21' is uninitialized when used within its own initialization}}
444*0a6a1f1dSLionel Sambuc B b22 = moveB(std::move(b22)); // expected-warning {{variable 'b22' is uninitialized when used within its own initialization}}
445*0a6a1f1dSLionel Sambuc B b23 = B(std::move(b23)); // expected-warning {{variable 'b23' is uninitialized when used within its own initialization}}
446*0a6a1f1dSLionel Sambuc B b24 = std::move(x ? b23 : (18, b24)); // expected-warning {{variable 'b24' is uninitialized when used within its own initialization}}
447f4a2713aSLionel Sambuc }
448f4a2713aSLionel Sambuc
449f4a2713aSLionel Sambuc B b1;
450f4a2713aSLionel Sambuc B b2(b1);
451f4a2713aSLionel Sambuc B b3 = { 5, &b3.x };
452f4a2713aSLionel Sambuc B b4 = getB();
453f4a2713aSLionel Sambuc B b5 = getB(&b5);
454f4a2713aSLionel Sambuc B b6 = getB(&b6.x);
455f4a2713aSLionel Sambuc
456f4a2713aSLionel Sambuc B b7(b7); // expected-warning {{variable 'b7' is uninitialized when used within its own initialization}}
457f4a2713aSLionel Sambuc B b8 = getB(b8.x); // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}}
458f4a2713aSLionel Sambuc B b9 = getB(b9.y); // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}}
459f4a2713aSLionel Sambuc B b10 = getB(-b10.x); // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}}
460f4a2713aSLionel Sambuc
461f4a2713aSLionel Sambuc B* b11 = 0;
462f4a2713aSLionel Sambuc B* b12(b11);
463f4a2713aSLionel Sambuc B* b13 = getPtrB();
464f4a2713aSLionel Sambuc B* b14 = getPtrB(&b14);
465f4a2713aSLionel Sambuc
466f4a2713aSLionel Sambuc B* b15 = getPtrB(b15->x); // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}}
467f4a2713aSLionel Sambuc B* b16 = getPtrB(b16->y); // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}}
468f4a2713aSLionel Sambuc
469f4a2713aSLionel Sambuc B b17 = { b17.x = 5, b17.y = 0 };
470f4a2713aSLionel Sambuc B b18 = { b18.x + 1, b18.y }; // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}}
471f4a2713aSLionel Sambuc
472*0a6a1f1dSLionel Sambuc const B b19 = b19; // expected-warning {{variable 'b19' is uninitialized when used within its own initialization}}
473*0a6a1f1dSLionel Sambuc const B b20(b20); // expected-warning {{variable 'b20' is uninitialized when used within its own initialization}}
474f4a2713aSLionel Sambuc
475*0a6a1f1dSLionel Sambuc B b21 = std::move(b21); // expected-warning {{variable 'b21' is uninitialized when used within its own initialization}}
476*0a6a1f1dSLionel Sambuc B b22 = moveB(std::move(b22)); // expected-warning {{variable 'b22' is uninitialized when used within its own initialization}}
477*0a6a1f1dSLionel Sambuc B b23 = B(std::move(b23)); // expected-warning {{variable 'b23' is uninitialized when used within its own initialization}}
478*0a6a1f1dSLionel Sambuc B b24 = std::move(x ? b23 : (18, b24)); // expected-warning {{variable 'b24' is uninitialized when used within its own initialization}}
479f4a2713aSLionel Sambuc
480*0a6a1f1dSLionel Sambuc class U {
481*0a6a1f1dSLionel Sambuc B b1, b2;
482*0a6a1f1dSLionel Sambuc B *ptr1, *ptr2;
483*0a6a1f1dSLionel Sambuc const B constb = {};
484f4a2713aSLionel Sambuc
U()485*0a6a1f1dSLionel Sambuc U() {}
U(bool (*)[1])486*0a6a1f1dSLionel Sambuc U(bool (*)[1]) : b1() {}
U(bool (*)[2])487*0a6a1f1dSLionel Sambuc U(bool (*)[2]) : b2(b1) {}
U(bool (*)[3])488*0a6a1f1dSLionel Sambuc U(bool (*)[3]) : b1{ 5, &b1.x } {}
U(bool (*)[4])489*0a6a1f1dSLionel Sambuc U(bool (*)[4]) : b1(getB()) {}
U(bool (*)[5])490*0a6a1f1dSLionel Sambuc U(bool (*)[5]) : b1(getB(&b1)) {}
U(bool (*)[6])491*0a6a1f1dSLionel Sambuc U(bool (*)[6]) : b1(getB(&b1.x)) {}
492*0a6a1f1dSLionel Sambuc
U(bool (*)[7])493*0a6a1f1dSLionel Sambuc U(bool (*)[7]) : b1(b1) {} // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[8])494*0a6a1f1dSLionel Sambuc U(bool (*)[8]) : b1(getB(b1.x)) {} // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[9])495*0a6a1f1dSLionel Sambuc U(bool (*)[9]) : b1(getB(b1.y)) {} // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[10])496*0a6a1f1dSLionel Sambuc U(bool (*)[10]) : b1(getB(-b1.x)) {} // expected-warning {{field 'b1' is uninitialized when used here}}
497*0a6a1f1dSLionel Sambuc
U(bool (*)[11])498*0a6a1f1dSLionel Sambuc U(bool (*)[11]) : ptr1(0) {}
U(bool (*)[12])499*0a6a1f1dSLionel Sambuc U(bool (*)[12]) : ptr1(0), ptr2(ptr1) {}
U(bool (*)[13])500*0a6a1f1dSLionel Sambuc U(bool (*)[13]) : ptr1(getPtrB()) {}
U(bool (*)[14])501*0a6a1f1dSLionel Sambuc U(bool (*)[14]) : ptr1(getPtrB(&ptr1)) {}
502*0a6a1f1dSLionel Sambuc
U(bool (*)[15])503*0a6a1f1dSLionel Sambuc U(bool (*)[15]) : ptr1(getPtrB(ptr1->x)) {} // expected-warning {{field 'ptr1' is uninitialized when used here}}
U(bool (*)[16])504*0a6a1f1dSLionel Sambuc U(bool (*)[16]) : ptr2(getPtrB(ptr2->y)) {} // expected-warning {{field 'ptr2' is uninitialized when used here}}
505*0a6a1f1dSLionel Sambuc
U(bool (*)[17])506*0a6a1f1dSLionel Sambuc U(bool (*)[17]) : b1 { b1.x = 5, b1.y = 0 } {}
U(bool (*)[18])507*0a6a1f1dSLionel Sambuc U(bool (*)[18]) : b1 { b1.x + 1, b1.y } {} // expected-warning 2{{field 'b1' is uninitialized when used here}}
508*0a6a1f1dSLionel Sambuc
U(bool (*)[19])509*0a6a1f1dSLionel Sambuc U(bool (*)[19]) : constb(constb) {} // expected-warning {{field 'constb' is uninitialized when used here}}
U(bool (*)[20])510*0a6a1f1dSLionel Sambuc U(bool (*)[20]) : constb(B(constb)) {} // expected-warning {{field 'constb' is uninitialized when used here}}
511*0a6a1f1dSLionel Sambuc
U(bool (*)[21])512*0a6a1f1dSLionel Sambuc U(bool (*)[21]) : b1(std::move(b1)) {} // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[22])513*0a6a1f1dSLionel Sambuc U(bool (*)[22]) : b1(moveB(std::move(b1))) {} // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[23])514*0a6a1f1dSLionel Sambuc U(bool (*)[23]) : b1(B(std::move(b1))) {} // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[24])515*0a6a1f1dSLionel Sambuc U(bool (*)[24]) : b2(std::move(x ? b1 : (18, b2))) {} // expected-warning {{field 'b2' is uninitialized when used here}}
516f4a2713aSLionel Sambuc };
517f4a2713aSLionel Sambuc
518f4a2713aSLionel Sambuc struct C { char a[100], *e; } car = { .e = car.a };
519f4a2713aSLionel Sambuc
520f4a2713aSLionel Sambuc // <rdar://problem/10398199>
521f4a2713aSLionel Sambuc namespace rdar10398199 {
~FooBase()522f4a2713aSLionel Sambuc class FooBase { protected: ~FooBase() {} };
523f4a2713aSLionel Sambuc class Foo : public FooBase {
524f4a2713aSLionel Sambuc public:
525f4a2713aSLionel Sambuc operator int&() const;
526f4a2713aSLionel Sambuc };
527f4a2713aSLionel Sambuc void stuff();
528f4a2713aSLionel Sambuc template <typename T> class FooImpl : public Foo {
529f4a2713aSLionel Sambuc T val;
530f4a2713aSLionel Sambuc public:
FooImpl(const T & x)531f4a2713aSLionel Sambuc FooImpl(const T &x) : val(x) {}
~FooImpl()532f4a2713aSLionel Sambuc ~FooImpl() { stuff(); }
533f4a2713aSLionel Sambuc };
534f4a2713aSLionel Sambuc
makeFoo(const T & x)535f4a2713aSLionel Sambuc template <typename T> FooImpl<T> makeFoo(const T& x) {
536f4a2713aSLionel Sambuc return FooImpl<T>(x);
537f4a2713aSLionel Sambuc }
538f4a2713aSLionel Sambuc
test()539f4a2713aSLionel Sambuc void test() {
540f4a2713aSLionel Sambuc const Foo &x = makeFoo(42);
541f4a2713aSLionel Sambuc const int&y = makeFoo(42u);
542f4a2713aSLionel Sambuc (void)x;
543f4a2713aSLionel Sambuc (void)y;
544f4a2713aSLionel Sambuc };
545f4a2713aSLionel Sambuc }
546f4a2713aSLionel Sambuc
547f4a2713aSLionel Sambuc // PR 12325 - this was a false uninitialized value warning due to
548f4a2713aSLionel Sambuc // a broken CFG.
pr12325(int params)549f4a2713aSLionel Sambuc int pr12325(int params) {
550f4a2713aSLionel Sambuc int x = ({
551f4a2713aSLionel Sambuc while (false)
552f4a2713aSLionel Sambuc ;
553f4a2713aSLionel Sambuc int _v = params;
554f4a2713aSLionel Sambuc if (false)
555f4a2713aSLionel Sambuc ;
556f4a2713aSLionel Sambuc _v; // no-warning
557f4a2713aSLionel Sambuc });
558f4a2713aSLionel Sambuc return x;
559f4a2713aSLionel Sambuc }
560f4a2713aSLionel Sambuc
561f4a2713aSLionel Sambuc // Test lambda expressions with -Wuninitialized
test_lambda()562f4a2713aSLionel Sambuc int test_lambda() {
563f4a2713aSLionel Sambuc auto f1 = [] (int x, int y) { int z; return x + y + z; }; // expected-warning{{variable 'z' is uninitialized when used here}} expected-note {{initialize the variable 'z' to silence this warning}}
564f4a2713aSLionel Sambuc return f1(1, 2);
565f4a2713aSLionel Sambuc }
566f4a2713aSLionel Sambuc
567f4a2713aSLionel Sambuc namespace {
568f4a2713aSLionel Sambuc struct A {
569f4a2713aSLionel Sambuc enum { A1 };
A2__anonf08c3b8f0211::A570f4a2713aSLionel Sambuc static int A2() {return 5;}
571f4a2713aSLionel Sambuc int A3;
A4__anonf08c3b8f0211::A572f4a2713aSLionel Sambuc int A4() { return 5;}
573f4a2713aSLionel Sambuc };
574f4a2713aSLionel Sambuc
575f4a2713aSLionel Sambuc struct B {
576f4a2713aSLionel Sambuc A a;
577f4a2713aSLionel Sambuc };
578f4a2713aSLionel Sambuc
579f4a2713aSLionel Sambuc struct C {
C__anonf08c3b8f0211::C580f4a2713aSLionel Sambuc C() {}
C__anonf08c3b8f0211::C581f4a2713aSLionel Sambuc C(int x) {}
582f4a2713aSLionel Sambuc static A a;
583f4a2713aSLionel Sambuc B b;
584f4a2713aSLionel Sambuc };
585f4a2713aSLionel Sambuc A C::a = A();
586f4a2713aSLionel Sambuc
587f4a2713aSLionel Sambuc // Accessing non-static members will give a warning.
588f4a2713aSLionel Sambuc struct D {
589f4a2713aSLionel Sambuc C c;
D__anonf08c3b8f0211::D590f4a2713aSLionel Sambuc D(char (*)[1]) : c(c.b.a.A1) {}
D__anonf08c3b8f0211::D591f4a2713aSLionel Sambuc D(char (*)[2]) : c(c.b.a.A2()) {}
D__anonf08c3b8f0211::D592f4a2713aSLionel Sambuc D(char (*)[3]) : c(c.b.a.A3) {} // expected-warning {{field 'c' is uninitialized when used here}}
D__anonf08c3b8f0211::D593f4a2713aSLionel Sambuc D(char (*)[4]) : c(c.b.a.A4()) {} // expected-warning {{field 'c' is uninitialized when used here}}
594f4a2713aSLionel Sambuc
595f4a2713aSLionel Sambuc // c::a is static, so it is already initialized
D__anonf08c3b8f0211::D596f4a2713aSLionel Sambuc D(char (*)[5]) : c(c.a.A1) {}
D__anonf08c3b8f0211::D597f4a2713aSLionel Sambuc D(char (*)[6]) : c(c.a.A2()) {}
D__anonf08c3b8f0211::D598f4a2713aSLionel Sambuc D(char (*)[7]) : c(c.a.A3) {}
D__anonf08c3b8f0211::D599f4a2713aSLionel Sambuc D(char (*)[8]) : c(c.a.A4()) {}
600f4a2713aSLionel Sambuc };
601f4a2713aSLionel Sambuc
602f4a2713aSLionel Sambuc struct E {
603f4a2713aSLionel Sambuc int b = 1;
604f4a2713aSLionel Sambuc int c = 1;
605f4a2713aSLionel Sambuc int a; // This field needs to be last to prevent the cross field
606f4a2713aSLionel Sambuc // uninitialized warning.
E__anonf08c3b8f0211::E607f4a2713aSLionel Sambuc E(char (*)[1]) : a(a ? b : c) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E608f4a2713aSLionel Sambuc E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E609f4a2713aSLionel Sambuc E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E610f4a2713aSLionel Sambuc E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E611f4a2713aSLionel Sambuc E(char (*)[5]) : a(b ? c : b) {}
612f4a2713aSLionel Sambuc
E__anonf08c3b8f0211::E613f4a2713aSLionel Sambuc E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E614f4a2713aSLionel Sambuc E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E615f4a2713aSLionel Sambuc E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E616f4a2713aSLionel Sambuc E(char (*)[9]) : a(b ?: c) {}
617f4a2713aSLionel Sambuc
E__anonf08c3b8f0211::E618f4a2713aSLionel Sambuc E(char (*)[10]) : a((a, a, b)) {}
E__anonf08c3b8f0211::E619f4a2713aSLionel Sambuc E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E620f4a2713aSLionel Sambuc E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E621f4a2713aSLionel Sambuc E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E622f4a2713aSLionel Sambuc E(char (*)[14]) : a((b, c, c)) {}
E__anonf08c3b8f0211::E623*0a6a1f1dSLionel Sambuc E(char (*)[15]) : a(b ?: a) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anonf08c3b8f0211::E624*0a6a1f1dSLionel Sambuc E(char (*)[16]) : a(a ?: b) {} // expected-warning {{field 'a' is uninitialized when used here}}
625f4a2713aSLionel Sambuc };
626f4a2713aSLionel Sambuc
627f4a2713aSLionel Sambuc struct F {
628f4a2713aSLionel Sambuc int a;
629f4a2713aSLionel Sambuc F* f;
F__anonf08c3b8f0211::F630f4a2713aSLionel Sambuc F(int) {}
F__anonf08c3b8f0211::F631f4a2713aSLionel Sambuc F() {}
632f4a2713aSLionel Sambuc };
633f4a2713aSLionel Sambuc
634f4a2713aSLionel Sambuc int F::*ptr = &F::a;
635f4a2713aSLionel Sambuc F* F::*f_ptr = &F::f;
636f4a2713aSLionel Sambuc struct G {
637f4a2713aSLionel Sambuc F f1, f2;
638f4a2713aSLionel Sambuc F *f3, *f4;
G__anonf08c3b8f0211::G639f4a2713aSLionel Sambuc G(char (*)[1]) : f1(f1) {} // expected-warning {{field 'f1' is uninitialized when used here}}
G__anonf08c3b8f0211::G640f4a2713aSLionel Sambuc G(char (*)[2]) : f2(f1) {}
G__anonf08c3b8f0211::G641f4a2713aSLionel Sambuc G(char (*)[3]) : f2(F()) {}
642f4a2713aSLionel Sambuc
G__anonf08c3b8f0211::G643f4a2713aSLionel Sambuc G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field 'f1' is uninitialized when used here}}
G__anonf08c3b8f0211::G644f4a2713aSLionel Sambuc G(char (*)[5]) : f2(f1.*ptr) {}
645f4a2713aSLionel Sambuc
G__anonf08c3b8f0211::G646f4a2713aSLionel Sambuc G(char (*)[6]) : f3(f3) {} // expected-warning {{field 'f3' is uninitialized when used here}}
G__anonf08c3b8f0211::G647f4a2713aSLionel Sambuc G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field 'f3' is uninitialized when used here}}
G__anonf08c3b8f0211::G648f4a2713aSLionel Sambuc G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field 'f3' is uninitialized when used here}}
649f4a2713aSLionel Sambuc };
650*0a6a1f1dSLionel Sambuc
651*0a6a1f1dSLionel Sambuc struct H {
H__anonf08c3b8f0211::H652*0a6a1f1dSLionel Sambuc H() : a(a) {} // expected-warning {{field 'a' is uninitialized when used here}}
653*0a6a1f1dSLionel Sambuc const A a;
654*0a6a1f1dSLionel Sambuc };
655f4a2713aSLionel Sambuc }
656f4a2713aSLionel Sambuc
657f4a2713aSLionel Sambuc namespace statics {
658f4a2713aSLionel Sambuc static int a = a; // no-warning: used to signal intended lack of initialization.
659f4a2713aSLionel Sambuc static int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
660f4a2713aSLionel Sambuc static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}}
661f4a2713aSLionel Sambuc static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
662f4a2713aSLionel Sambuc static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
663f4a2713aSLionel Sambuc
664f4a2713aSLionel Sambuc // Thes don't warn as they don't require the value.
665f4a2713aSLionel Sambuc static int g = sizeof(g);
666f4a2713aSLionel Sambuc int gg = g; // Silence unneeded warning
667f4a2713aSLionel Sambuc static void* ptr = &ptr;
668f4a2713aSLionel Sambuc static int h = bar(&h);
669f4a2713aSLionel Sambuc static int i = boo(i);
670f4a2713aSLionel Sambuc static int j = far(j);
671f4a2713aSLionel Sambuc static int k = __alignof__(k);
672f4a2713aSLionel Sambuc
673f4a2713aSLionel Sambuc static int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}}
674f4a2713aSLionel Sambuc static int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}}
675f4a2713aSLionel Sambuc static int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
676*0a6a1f1dSLionel Sambuc static int o = std::move(o); // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
677*0a6a1f1dSLionel Sambuc static const int p = std::move(p); // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
678*0a6a1f1dSLionel Sambuc static int q = moved(std::move(q)); // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
679*0a6a1f1dSLionel Sambuc static int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
680*0a6a1f1dSLionel Sambuc static int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
681*0a6a1f1dSLionel Sambuc static int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
682*0a6a1f1dSLionel Sambuc static int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
683*0a6a1f1dSLionel Sambuc static int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
684*0a6a1f1dSLionel Sambuc static int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
685*0a6a1f1dSLionel Sambuc static int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
686*0a6a1f1dSLionel Sambuc static int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
687*0a6a1f1dSLionel Sambuc static int z = ++ref(z); // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
688*0a6a1f1dSLionel Sambuc static int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
689*0a6a1f1dSLionel Sambuc static int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
690*0a6a1f1dSLionel Sambuc
691f4a2713aSLionel Sambuc
test()692f4a2713aSLionel Sambuc void test() {
693f4a2713aSLionel Sambuc static int a = a; // no-warning: used to signal intended lack of initialization.
694f4a2713aSLionel Sambuc static int b = b + 1; // expected-warning {{static variable 'b' is suspiciously used within its own initialization}}
695f4a2713aSLionel Sambuc static int c = (c + c); // expected-warning 2{{static variable 'c' is suspiciously used within its own initialization}}
696f4a2713aSLionel Sambuc static int d = ({ d + d ;}); // expected-warning 2{{static variable 'd' is suspiciously used within its own initialization}}
697f4a2713aSLionel Sambuc static int e = static_cast<long>(e) + 1; // expected-warning {{static variable 'e' is suspiciously used within its own initialization}}
698f4a2713aSLionel Sambuc static int f = foo(f); // expected-warning {{static variable 'f' is suspiciously used within its own initialization}}
699f4a2713aSLionel Sambuc
700f4a2713aSLionel Sambuc // Thes don't warn as they don't require the value.
701f4a2713aSLionel Sambuc static int g = sizeof(g);
702f4a2713aSLionel Sambuc static void* ptr = &ptr;
703f4a2713aSLionel Sambuc static int h = bar(&h);
704f4a2713aSLionel Sambuc static int i = boo(i);
705f4a2713aSLionel Sambuc static int j = far(j);
706f4a2713aSLionel Sambuc static int k = __alignof__(k);
707f4a2713aSLionel Sambuc
708f4a2713aSLionel Sambuc static int l = k ? l : l; // expected-warning 2{{static variable 'l' is suspiciously used within its own initialization}}
709f4a2713aSLionel Sambuc static int m = 1 + (k ? m : m); // expected-warning 2{{static variable 'm' is suspiciously used within its own initialization}}
710f4a2713aSLionel Sambuc static int n = -n; // expected-warning {{static variable 'n' is suspiciously used within its own initialization}}
711*0a6a1f1dSLionel Sambuc static int o = std::move(o); // expected-warning {{static variable 'o' is suspiciously used within its own initialization}}
712*0a6a1f1dSLionel Sambuc static const int p = std::move(p); // expected-warning {{static variable 'p' is suspiciously used within its own initialization}}
713*0a6a1f1dSLionel Sambuc static int q = moved(std::move(q)); // expected-warning {{static variable 'q' is suspiciously used within its own initialization}}
714*0a6a1f1dSLionel Sambuc static int r = std::move((p ? q : (18, r))); // expected-warning {{static variable 'r' is suspiciously used within its own initialization}}
715*0a6a1f1dSLionel Sambuc static int s = r ?: s; // expected-warning {{static variable 's' is suspiciously used within its own initialization}}
716*0a6a1f1dSLionel Sambuc static int t = t ?: s; // expected-warning {{static variable 't' is suspiciously used within its own initialization}}
717*0a6a1f1dSLionel Sambuc static int u = (foo(u), s); // expected-warning {{static variable 'u' is suspiciously used within its own initialization}}
718*0a6a1f1dSLionel Sambuc static int v = (u += v); // expected-warning {{static variable 'v' is suspiciously used within its own initialization}}
719*0a6a1f1dSLionel Sambuc static int w = (w += 10); // expected-warning {{static variable 'w' is suspiciously used within its own initialization}}
720*0a6a1f1dSLionel Sambuc static int x = x++; // expected-warning {{static variable 'x' is suspiciously used within its own initialization}}
721*0a6a1f1dSLionel Sambuc static int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{static variable 'y' is suspiciously used within its own initialization}}
722*0a6a1f1dSLionel Sambuc static int z = ++ref(z); // expected-warning {{static variable 'z' is suspiciously used within its own initialization}}
723*0a6a1f1dSLionel Sambuc static int aa = (ref(aa) += 10); // expected-warning {{static variable 'aa' is suspiciously used within its own initialization}}
724*0a6a1f1dSLionel Sambuc static int bb = bb ? x : y; // expected-warning {{static variable 'bb' is suspiciously used within its own initialization}}
725*0a6a1f1dSLionel Sambuc
726f4a2713aSLionel Sambuc for (;;) {
727f4a2713aSLionel Sambuc static int a = a; // no-warning: used to signal intended lack of initialization.
728f4a2713aSLionel Sambuc static int b = b + 1; // expected-warning {{static variable 'b' is suspiciously used within its own initialization}}
729f4a2713aSLionel Sambuc static int c = (c + c); // expected-warning 2{{static variable 'c' is suspiciously used within its own initialization}}
730f4a2713aSLionel Sambuc static int d = ({ d + d ;}); // expected-warning 2{{static variable 'd' is suspiciously used within its own initialization}}
731f4a2713aSLionel Sambuc static int e = static_cast<long>(e) + 1; // expected-warning {{static variable 'e' is suspiciously used within its own initialization}}
732f4a2713aSLionel Sambuc static int f = foo(f); // expected-warning {{static variable 'f' is suspiciously used within its own initialization}}
733f4a2713aSLionel Sambuc
734f4a2713aSLionel Sambuc // Thes don't warn as they don't require the value.
735f4a2713aSLionel Sambuc static int g = sizeof(g);
736f4a2713aSLionel Sambuc static void* ptr = &ptr;
737f4a2713aSLionel Sambuc static int h = bar(&h);
738f4a2713aSLionel Sambuc static int i = boo(i);
739f4a2713aSLionel Sambuc static int j = far(j);
740f4a2713aSLionel Sambuc static int k = __alignof__(k);
741f4a2713aSLionel Sambuc
742f4a2713aSLionel Sambuc static int l = k ? l : l; // expected-warning 2{{static variable 'l' is suspiciously used within its own initialization}}
743f4a2713aSLionel Sambuc static int m = 1 + (k ? m : m); // expected-warning 2{{static variable 'm' is suspiciously used within its own initialization}}
744f4a2713aSLionel Sambuc static int n = -n; // expected-warning {{static variable 'n' is suspiciously used within its own initialization}}
745*0a6a1f1dSLionel Sambuc static int o = std::move(o); // expected-warning {{static variable 'o' is suspiciously used within its own initialization}}
746*0a6a1f1dSLionel Sambuc static const int p = std::move(p); // expected-warning {{static variable 'p' is suspiciously used within its own initialization}}
747*0a6a1f1dSLionel Sambuc static int q = moved(std::move(q)); // expected-warning {{static variable 'q' is suspiciously used within its own initialization}}
748*0a6a1f1dSLionel Sambuc static int r = std::move((p ? q : (18, r))); // expected-warning {{static variable 'r' is suspiciously used within its own initialization}}
749*0a6a1f1dSLionel Sambuc static int s = r ?: s; // expected-warning {{static variable 's' is suspiciously used within its own initialization}}
750*0a6a1f1dSLionel Sambuc static int t = t ?: s; // expected-warning {{static variable 't' is suspiciously used within its own initialization}}
751*0a6a1f1dSLionel Sambuc static int u = (foo(u), s); // expected-warning {{static variable 'u' is suspiciously used within its own initialization}}
752*0a6a1f1dSLionel Sambuc static int v = (u += v); // expected-warning {{static variable 'v' is suspiciously used within its own initialization}}
753*0a6a1f1dSLionel Sambuc static int w = (w += 10); // expected-warning {{static variable 'w' is suspiciously used within its own initialization}}
754*0a6a1f1dSLionel Sambuc static int x = x++; // expected-warning {{static variable 'x' is suspiciously used within its own initialization}}
755*0a6a1f1dSLionel Sambuc static int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{static variable 'y' is suspiciously used within its own initialization}}
756*0a6a1f1dSLionel Sambuc static int z = ++ref(z); // expected-warning {{static variable 'z' is suspiciously used within its own initialization}}
757*0a6a1f1dSLionel Sambuc static int aa = (ref(aa) += 10); // expected-warning {{static variable 'aa' is suspiciously used within its own initialization}}
758*0a6a1f1dSLionel Sambuc static int bb = bb ? x : y; // expected-warning {{static variable 'bb' is suspiciously used within its own initialization}}
759f4a2713aSLionel Sambuc }
760f4a2713aSLionel Sambuc }
761f4a2713aSLionel Sambuc }
762f4a2713aSLionel Sambuc
763f4a2713aSLionel Sambuc namespace in_class_initializers {
764f4a2713aSLionel Sambuc struct S {
Sin_class_initializers::S765f4a2713aSLionel Sambuc S() : a(a + 1) {} // expected-warning{{field 'a' is uninitialized when used here}}
766f4a2713aSLionel Sambuc int a = 42; // Note: because a is in a member initializer list, this initialization is ignored.
767f4a2713aSLionel Sambuc };
768f4a2713aSLionel Sambuc
769f4a2713aSLionel Sambuc struct T {
Tin_class_initializers::T770f4a2713aSLionel Sambuc T() : b(a + 1) {} // No-warning.
771f4a2713aSLionel Sambuc int a = 42;
772f4a2713aSLionel Sambuc int b;
773f4a2713aSLionel Sambuc };
774f4a2713aSLionel Sambuc
775f4a2713aSLionel Sambuc struct U {
Uin_class_initializers::U776f4a2713aSLionel Sambuc U() : a(b + 1), b(a + 1) {} // expected-warning{{field 'b' is uninitialized when used here}}
777f4a2713aSLionel Sambuc int a = 42; // Note: because a and b are in the member initializer list, these initializers are ignored.
778f4a2713aSLionel Sambuc int b = 1;
779f4a2713aSLionel Sambuc };
780f4a2713aSLionel Sambuc }
781f4a2713aSLionel Sambuc
782f4a2713aSLionel Sambuc namespace references {
783f4a2713aSLionel Sambuc int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}}
784f4a2713aSLionel Sambuc int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}}
785f4a2713aSLionel Sambuc int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}}
786f4a2713aSLionel Sambuc int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}}
787*0a6a1f1dSLionel Sambuc int &e = d ?: e; // expected-warning{{reference 'e' is not yet bound to a value when used within its own initialization}}
788*0a6a1f1dSLionel Sambuc int &f = f ?: d; // expected-warning{{reference 'f' is not yet bound to a value when used within its own initialization}}
789*0a6a1f1dSLionel Sambuc
790*0a6a1f1dSLionel Sambuc int &return_ref1(int);
791*0a6a1f1dSLionel Sambuc int &return_ref2(int&);
792*0a6a1f1dSLionel Sambuc
793*0a6a1f1dSLionel Sambuc int &g = return_ref1(g); // expected-warning{{reference 'g' is not yet bound to a value when used within its own initialization}}
794*0a6a1f1dSLionel Sambuc int &h = return_ref2(h); // expected-warning{{reference 'h' is not yet bound to a value when used within its own initialization}}
795f4a2713aSLionel Sambuc
796f4a2713aSLionel Sambuc struct S {
Sreferences::S797f4a2713aSLionel Sambuc S() : a(a) {} // expected-warning{{reference 'a' is not yet bound to a value when used here}}
798f4a2713aSLionel Sambuc int &a;
799f4a2713aSLionel Sambuc };
800f4a2713aSLionel Sambuc
test()801*0a6a1f1dSLionel Sambuc void test() {
802f4a2713aSLionel Sambuc int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}}
803f4a2713aSLionel Sambuc int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}}
804f4a2713aSLionel Sambuc int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}}
805f4a2713aSLionel Sambuc int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}}
806f4a2713aSLionel Sambuc }
807f4a2713aSLionel Sambuc
808f4a2713aSLionel Sambuc struct T {
Treferences::T809f4a2713aSLionel Sambuc T() // expected-note{{during field initialization in this constructor}}
810f4a2713aSLionel Sambuc : a(b), b(a) {} // expected-warning{{reference 'b' is not yet bound to a value when used here}}
811f4a2713aSLionel Sambuc int &a, &b;
812f4a2713aSLionel Sambuc int &c = c; // expected-warning{{reference 'c' is not yet bound to a value when used here}}
813f4a2713aSLionel Sambuc };
814f4a2713aSLionel Sambuc
815f4a2713aSLionel Sambuc int x;
816f4a2713aSLionel Sambuc struct U {
Ureferences::U817f4a2713aSLionel Sambuc U() : b(a) {} // No-warning.
818f4a2713aSLionel Sambuc int &a = x;
819f4a2713aSLionel Sambuc int &b;
820f4a2713aSLionel Sambuc };
821f4a2713aSLionel Sambuc }
822f4a2713aSLionel Sambuc
823f4a2713aSLionel Sambuc namespace operators {
824f4a2713aSLionel Sambuc struct A {
825f4a2713aSLionel Sambuc A(bool);
826f4a2713aSLionel Sambuc bool operator==(A);
827f4a2713aSLionel Sambuc };
828f4a2713aSLionel Sambuc
829f4a2713aSLionel Sambuc A makeA();
830f4a2713aSLionel Sambuc
831f4a2713aSLionel Sambuc A a1 = a1 = makeA(); // expected-warning{{variable 'a1' is uninitialized when used within its own initialization}}
832f4a2713aSLionel Sambuc A a2 = a2 == a1; // expected-warning{{variable 'a2' is uninitialized when used within its own initialization}}
833f4a2713aSLionel Sambuc A a3 = a2 == a3; // expected-warning{{variable 'a3' is uninitialized when used within its own initialization}}
834f4a2713aSLionel Sambuc
835f4a2713aSLionel Sambuc int x = x = 5;
836f4a2713aSLionel Sambuc }
837f4a2713aSLionel Sambuc
838f4a2713aSLionel Sambuc namespace lambdas {
839f4a2713aSLionel Sambuc struct A {
Alambdas::A840f4a2713aSLionel Sambuc template<typename T> A(T) {}
841f4a2713aSLionel Sambuc int x;
842f4a2713aSLionel Sambuc };
__anonf08c3b8f0402null843f4a2713aSLionel Sambuc A a0([] { return a0.x; }); // ok
f()844f4a2713aSLionel Sambuc void f() {
845f4a2713aSLionel Sambuc A a1([=] { return a1.x; }); // expected-warning{{variable 'a1' is uninitialized when used within its own initialization}}
846f4a2713aSLionel Sambuc A a2([&] { return a2.x; }); // ok
847f4a2713aSLionel Sambuc }
848f4a2713aSLionel Sambuc }
849f4a2713aSLionel Sambuc
850f4a2713aSLionel Sambuc namespace record_fields {
851*0a6a1f1dSLionel Sambuc bool x;
852f4a2713aSLionel Sambuc struct A {
Arecord_fields::A853f4a2713aSLionel Sambuc A() {}
854f4a2713aSLionel Sambuc A get();
855f4a2713aSLionel Sambuc static A num();
856f4a2713aSLionel Sambuc static A copy(A);
857f4a2713aSLionel Sambuc static A something(A&);
858f4a2713aSLionel Sambuc };
859f4a2713aSLionel Sambuc
860f4a2713aSLionel Sambuc A ref(A&);
861f4a2713aSLionel Sambuc A const_ref(const A&);
862f4a2713aSLionel Sambuc A pointer(A*);
863f4a2713aSLionel Sambuc A normal(A);
864*0a6a1f1dSLionel Sambuc A rref(A&&);
865f4a2713aSLionel Sambuc
866f4a2713aSLionel Sambuc struct B {
867f4a2713aSLionel Sambuc A a;
Brecord_fields::B868f4a2713aSLionel Sambuc B(char (*)[1]) : a(a) {} // expected-warning {{uninitialized}}
Brecord_fields::B869f4a2713aSLionel Sambuc B(char (*)[2]) : a(a.get()) {} // expected-warning {{uninitialized}}
Brecord_fields::B870f4a2713aSLionel Sambuc B(char (*)[3]) : a(a.num()) {}
Brecord_fields::B871f4a2713aSLionel Sambuc B(char (*)[4]) : a(a.copy(a)) {} // expected-warning {{uninitialized}}
Brecord_fields::B872f4a2713aSLionel Sambuc B(char (*)[5]) : a(a.something(a)) {}
Brecord_fields::B873f4a2713aSLionel Sambuc B(char (*)[6]) : a(ref(a)) {}
Brecord_fields::B874f4a2713aSLionel Sambuc B(char (*)[7]) : a(const_ref(a)) {}
Brecord_fields::B875f4a2713aSLionel Sambuc B(char (*)[8]) : a(pointer(&a)) {}
Brecord_fields::B876f4a2713aSLionel Sambuc B(char (*)[9]) : a(normal(a)) {} // expected-warning {{uninitialized}}
Brecord_fields::B877*0a6a1f1dSLionel Sambuc B(char (*)[10]) : a(std::move(a)) {} // expected-warning {{uninitialized}}
Brecord_fields::B878*0a6a1f1dSLionel Sambuc B(char (*)[11]) : a(A(std::move(a))) {} // expected-warning {{uninitialized}}
Brecord_fields::B879*0a6a1f1dSLionel Sambuc B(char (*)[12]) : a(rref(std::move(a))) {} // expected-warning {{uninitialized}}
Brecord_fields::B880*0a6a1f1dSLionel Sambuc B(char (*)[13]) : a(std::move(x ? a : (25, a))) {} // expected-warning 2{{uninitialized}}
881f4a2713aSLionel Sambuc };
882f4a2713aSLionel Sambuc struct C {
Crecord_fields::C883*0a6a1f1dSLionel Sambuc C() {} // expected-note9{{in this constructor}}
884f4a2713aSLionel Sambuc A a1 = a1; // expected-warning {{uninitialized}}
885f4a2713aSLionel Sambuc A a2 = a2.get(); // expected-warning {{uninitialized}}
886f4a2713aSLionel Sambuc A a3 = a3.num();
887f4a2713aSLionel Sambuc A a4 = a4.copy(a4); // expected-warning {{uninitialized}}
888f4a2713aSLionel Sambuc A a5 = a5.something(a5);
889f4a2713aSLionel Sambuc A a6 = ref(a6);
890f4a2713aSLionel Sambuc A a7 = const_ref(a7);
891f4a2713aSLionel Sambuc A a8 = pointer(&a8);
892f4a2713aSLionel Sambuc A a9 = normal(a9); // expected-warning {{uninitialized}}
893*0a6a1f1dSLionel Sambuc const A a10 = a10; // expected-warning {{uninitialized}}
894*0a6a1f1dSLionel Sambuc A a11 = std::move(a11); // expected-warning {{uninitialized}}
895*0a6a1f1dSLionel Sambuc A a12 = A(std::move(a12)); // expected-warning {{uninitialized}}
896*0a6a1f1dSLionel Sambuc A a13 = rref(std::move(a13)); // expected-warning {{uninitialized}}
897*0a6a1f1dSLionel Sambuc A a14 = std::move(x ? a13 : (22, a14)); // expected-warning {{uninitialized}}
898f4a2713aSLionel Sambuc };
899*0a6a1f1dSLionel Sambuc struct D { // expected-note9{{in the implicit default constructor}}
900f4a2713aSLionel Sambuc A a1 = a1; // expected-warning {{uninitialized}}
901f4a2713aSLionel Sambuc A a2 = a2.get(); // expected-warning {{uninitialized}}
902f4a2713aSLionel Sambuc A a3 = a3.num();
903f4a2713aSLionel Sambuc A a4 = a4.copy(a4); // expected-warning {{uninitialized}}
904f4a2713aSLionel Sambuc A a5 = a5.something(a5);
905f4a2713aSLionel Sambuc A a6 = ref(a6);
906f4a2713aSLionel Sambuc A a7 = const_ref(a7);
907f4a2713aSLionel Sambuc A a8 = pointer(&a8);
908f4a2713aSLionel Sambuc A a9 = normal(a9); // expected-warning {{uninitialized}}
909*0a6a1f1dSLionel Sambuc const A a10 = a10; // expected-warning {{uninitialized}}
910*0a6a1f1dSLionel Sambuc A a11 = std::move(a11); // expected-warning {{uninitialized}}
911*0a6a1f1dSLionel Sambuc A a12 = A(std::move(a12)); // expected-warning {{uninitialized}}
912*0a6a1f1dSLionel Sambuc A a13 = rref(std::move(a13)); // expected-warning {{uninitialized}}
913*0a6a1f1dSLionel Sambuc A a14 = std::move(x ? a13 : (22, a14)); // expected-warning {{uninitialized}}
914f4a2713aSLionel Sambuc };
915f4a2713aSLionel Sambuc D d;
916f4a2713aSLionel Sambuc struct E {
917f4a2713aSLionel Sambuc A a1 = a1;
918f4a2713aSLionel Sambuc A a2 = a2.get();
919f4a2713aSLionel Sambuc A a3 = a3.num();
920f4a2713aSLionel Sambuc A a4 = a4.copy(a4);
921f4a2713aSLionel Sambuc A a5 = a5.something(a5);
922f4a2713aSLionel Sambuc A a6 = ref(a6);
923f4a2713aSLionel Sambuc A a7 = const_ref(a7);
924f4a2713aSLionel Sambuc A a8 = pointer(&a8);
925f4a2713aSLionel Sambuc A a9 = normal(a9);
926*0a6a1f1dSLionel Sambuc const A a10 = a10;
927*0a6a1f1dSLionel Sambuc A a11 = std::move(a11);
928*0a6a1f1dSLionel Sambuc A a12 = A(std::move(a12));
929*0a6a1f1dSLionel Sambuc A a13 = rref(std::move(a13));
930*0a6a1f1dSLionel Sambuc A a14 = std::move(x ? a13 : (22, a14));
931f4a2713aSLionel Sambuc };
932f4a2713aSLionel Sambuc }
933f4a2713aSLionel Sambuc
934f4a2713aSLionel Sambuc namespace cross_field_warnings {
935f4a2713aSLionel Sambuc struct A {
936f4a2713aSLionel Sambuc int a, b;
Across_field_warnings::A937f4a2713aSLionel Sambuc A() {}
Across_field_warnings::A938f4a2713aSLionel Sambuc A(char (*)[1]) : b(a) {} // expected-warning{{field 'a' is uninitialized when used here}}
Across_field_warnings::A939f4a2713aSLionel Sambuc A(char (*)[2]) : a(b) {} // expected-warning{{field 'b' is uninitialized when used here}}
940f4a2713aSLionel Sambuc };
941f4a2713aSLionel Sambuc
942f4a2713aSLionel Sambuc struct B {
943f4a2713aSLionel Sambuc int a = b; // expected-warning{{field 'b' is uninitialized when used here}}
944f4a2713aSLionel Sambuc int b;
Bcross_field_warnings::B945f4a2713aSLionel Sambuc B() {} // expected-note{{during field initialization in this constructor}}
946f4a2713aSLionel Sambuc };
947f4a2713aSLionel Sambuc
948f4a2713aSLionel Sambuc struct C {
949f4a2713aSLionel Sambuc int a;
950f4a2713aSLionel Sambuc int b = a; // expected-warning{{field 'a' is uninitialized when used here}}
Ccross_field_warnings::C951f4a2713aSLionel Sambuc C(char (*)[1]) : a(5) {}
Ccross_field_warnings::C952f4a2713aSLionel Sambuc C(char (*)[2]) {} // expected-note{{during field initialization in this constructor}}
953f4a2713aSLionel Sambuc };
954f4a2713aSLionel Sambuc
955f4a2713aSLionel Sambuc struct D {
956f4a2713aSLionel Sambuc int a;
957f4a2713aSLionel Sambuc int &b;
958f4a2713aSLionel Sambuc int &c = a;
959f4a2713aSLionel Sambuc int d = b;
Dcross_field_warnings::D960f4a2713aSLionel Sambuc D() : b(a) {}
961f4a2713aSLionel Sambuc };
962f4a2713aSLionel Sambuc
963f4a2713aSLionel Sambuc struct E {
964f4a2713aSLionel Sambuc int a;
965f4a2713aSLionel Sambuc int get();
966f4a2713aSLionel Sambuc static int num();
Ecross_field_warnings::E967f4a2713aSLionel Sambuc E() {}
Ecross_field_warnings::E968f4a2713aSLionel Sambuc E(int) {}
969f4a2713aSLionel Sambuc };
970f4a2713aSLionel Sambuc
971f4a2713aSLionel Sambuc struct F {
972f4a2713aSLionel Sambuc int a;
973f4a2713aSLionel Sambuc E e;
974f4a2713aSLionel Sambuc int b;
Fcross_field_warnings::F975f4a2713aSLionel Sambuc F(char (*)[1]) : a(e.get()) {} // expected-warning{{field 'e' is uninitialized when used here}}
Fcross_field_warnings::F976f4a2713aSLionel Sambuc F(char (*)[2]) : a(e.num()) {}
Fcross_field_warnings::F977f4a2713aSLionel Sambuc F(char (*)[3]) : e(a) {} // expected-warning{{field 'a' is uninitialized when used here}}
Fcross_field_warnings::F978f4a2713aSLionel Sambuc F(char (*)[4]) : a(4), e(a) {}
Fcross_field_warnings::F979f4a2713aSLionel Sambuc F(char (*)[5]) : e(b) {} // expected-warning{{field 'b' is uninitialized when used here}}
Fcross_field_warnings::F980f4a2713aSLionel Sambuc F(char (*)[6]) : e(b), b(4) {} // expected-warning{{field 'b' is uninitialized when used here}}
981f4a2713aSLionel Sambuc };
982f4a2713aSLionel Sambuc
983f4a2713aSLionel Sambuc struct G {
Gcross_field_warnings::G984f4a2713aSLionel Sambuc G(const A&) {};
985f4a2713aSLionel Sambuc };
986f4a2713aSLionel Sambuc
987f4a2713aSLionel Sambuc struct H {
988f4a2713aSLionel Sambuc A a1;
989f4a2713aSLionel Sambuc G g;
990f4a2713aSLionel Sambuc A a2;
Hcross_field_warnings::H991f4a2713aSLionel Sambuc H() : g(a1) {}
Hcross_field_warnings::H992f4a2713aSLionel Sambuc H(int) : g(a2) {}
993f4a2713aSLionel Sambuc };
994f4a2713aSLionel Sambuc
995f4a2713aSLionel Sambuc struct I {
Icross_field_warnings::I996f4a2713aSLionel Sambuc I(int*) {}
997f4a2713aSLionel Sambuc };
998f4a2713aSLionel Sambuc
999f4a2713aSLionel Sambuc struct J : public I {
1000f4a2713aSLionel Sambuc int *a;
1001f4a2713aSLionel Sambuc int *b;
1002f4a2713aSLionel Sambuc int c;
Jcross_field_warnings::J1003f4a2713aSLionel Sambuc J() : I((a = new int(5))), b(a), c(*a) {}
1004f4a2713aSLionel Sambuc };
1005f4a2713aSLionel Sambuc
1006f4a2713aSLionel Sambuc struct K {
1007f4a2713aSLionel Sambuc int a = (b = 5);
1008f4a2713aSLionel Sambuc int b = b + 5;
1009f4a2713aSLionel Sambuc };
1010f4a2713aSLionel Sambuc
1011f4a2713aSLionel Sambuc struct L {
1012f4a2713aSLionel Sambuc int a = (b = 5);
1013f4a2713aSLionel Sambuc int b = b + 5; // expected-warning{{field 'b' is uninitialized when used here}}
Lcross_field_warnings::L1014f4a2713aSLionel Sambuc L() : a(5) {} // expected-note{{during field initialization in this constructor}}
1015f4a2713aSLionel Sambuc };
1016f4a2713aSLionel Sambuc
1017f4a2713aSLionel Sambuc struct M { };
1018f4a2713aSLionel Sambuc
1019f4a2713aSLionel Sambuc struct N : public M {
1020f4a2713aSLionel Sambuc int a;
1021f4a2713aSLionel Sambuc int b;
Ncross_field_warnings::N1022f4a2713aSLionel Sambuc N() : b(a) { } // expected-warning{{field 'a' is uninitialized when used here}}
1023f4a2713aSLionel Sambuc };
1024f4a2713aSLionel Sambuc
1025f4a2713aSLionel Sambuc struct O {
1026f4a2713aSLionel Sambuc int x = 42;
getcross_field_warnings::O1027f4a2713aSLionel Sambuc int get() { return x; }
1028f4a2713aSLionel Sambuc };
1029f4a2713aSLionel Sambuc
1030f4a2713aSLionel Sambuc struct P {
1031f4a2713aSLionel Sambuc O o;
1032f4a2713aSLionel Sambuc int x = o.get();
Pcross_field_warnings::P1033f4a2713aSLionel Sambuc P() : x(o.get()) { }
1034f4a2713aSLionel Sambuc };
1035f4a2713aSLionel Sambuc
1036f4a2713aSLionel Sambuc struct Q {
1037f4a2713aSLionel Sambuc int a;
1038f4a2713aSLionel Sambuc int b;
1039f4a2713aSLionel Sambuc int &c;
Qcross_field_warnings::Q1040f4a2713aSLionel Sambuc Q() :
1041f4a2713aSLionel Sambuc a(c = 5), // expected-warning{{reference 'c' is not yet bound to a value when used here}}
1042f4a2713aSLionel Sambuc b(c), // expected-warning{{reference 'c' is not yet bound to a value when used here}}
1043f4a2713aSLionel Sambuc c(a) {}
1044f4a2713aSLionel Sambuc };
1045f4a2713aSLionel Sambuc
1046f4a2713aSLionel Sambuc struct R {
1047f4a2713aSLionel Sambuc int a;
1048f4a2713aSLionel Sambuc int b;
1049f4a2713aSLionel Sambuc int c;
1050f4a2713aSLionel Sambuc int d = a + b + c;
Rcross_field_warnings::R1051f4a2713aSLionel Sambuc R() : a(c = 5), b(c), c(a) {}
1052f4a2713aSLionel Sambuc };
1053*0a6a1f1dSLionel Sambuc
1054*0a6a1f1dSLionel Sambuc // FIXME: Use the CFG-based analysis to give a sometimes uninitialized
1055*0a6a1f1dSLionel Sambuc // warning on y.
1056*0a6a1f1dSLionel Sambuc struct T {
1057*0a6a1f1dSLionel Sambuc int x;
1058*0a6a1f1dSLionel Sambuc int y;
Tcross_field_warnings::T1059*0a6a1f1dSLionel Sambuc T(bool b)
1060*0a6a1f1dSLionel Sambuc : x(b ? (y = 5) : (1 + y)), // expected-warning{{field 'y' is uninitialized when used here}}
1061*0a6a1f1dSLionel Sambuc y(y + 1) {}
Tcross_field_warnings::T1062*0a6a1f1dSLionel Sambuc T(int b)
1063*0a6a1f1dSLionel Sambuc : x(!b ? (1 + y) : (y = 5)), // expected-warning{{field 'y' is uninitialized when used here}}
1064*0a6a1f1dSLionel Sambuc y(y + 1) {}
1065*0a6a1f1dSLionel Sambuc };
1066*0a6a1f1dSLionel Sambuc
1067f4a2713aSLionel Sambuc }
1068f4a2713aSLionel Sambuc
1069f4a2713aSLionel Sambuc namespace base_class {
1070f4a2713aSLionel Sambuc struct A {
Abase_class::A1071f4a2713aSLionel Sambuc A (int) {}
1072f4a2713aSLionel Sambuc };
1073f4a2713aSLionel Sambuc
1074f4a2713aSLionel Sambuc struct B : public A {
1075f4a2713aSLionel Sambuc int x;
Bbase_class::B1076f4a2713aSLionel Sambuc B() : A(x) {} // expected-warning{{field 'x' is uninitialized when used here}}
1077f4a2713aSLionel Sambuc };
1078f4a2713aSLionel Sambuc
1079f4a2713aSLionel Sambuc struct C : public A {
1080f4a2713aSLionel Sambuc int x;
1081f4a2713aSLionel Sambuc int y;
Cbase_class::C1082f4a2713aSLionel Sambuc C() : A(y = 4), x(y) {}
1083f4a2713aSLionel Sambuc };
1084f4a2713aSLionel Sambuc }
1085*0a6a1f1dSLionel Sambuc
1086*0a6a1f1dSLionel Sambuc namespace delegating_constructor {
1087*0a6a1f1dSLionel Sambuc struct A {
1088*0a6a1f1dSLionel Sambuc A(int);
1089*0a6a1f1dSLionel Sambuc A(int&, int);
1090*0a6a1f1dSLionel Sambuc
Adelegating_constructor::A1091*0a6a1f1dSLionel Sambuc A(char (*)[1]) : A(x) {}
1092*0a6a1f1dSLionel Sambuc // expected-warning@-1 {{field 'x' is uninitialized when used here}}
Adelegating_constructor::A1093*0a6a1f1dSLionel Sambuc A(char (*)[2]) : A(x, x) {}
1094*0a6a1f1dSLionel Sambuc // expected-warning@-1 {{field 'x' is uninitialized when used here}}
1095*0a6a1f1dSLionel Sambuc
Adelegating_constructor::A1096*0a6a1f1dSLionel Sambuc A(char (*)[3]) : A(x, 0) {}
1097*0a6a1f1dSLionel Sambuc
1098*0a6a1f1dSLionel Sambuc int x;
1099*0a6a1f1dSLionel Sambuc };
1100*0a6a1f1dSLionel Sambuc }
1101*0a6a1f1dSLionel Sambuc
1102*0a6a1f1dSLionel Sambuc namespace init_list {
1103*0a6a1f1dSLionel Sambuc int num = 5;
1104*0a6a1f1dSLionel Sambuc struct A { int i1, i2; };
1105*0a6a1f1dSLionel Sambuc struct B { A a1, a2; };
1106*0a6a1f1dSLionel Sambuc
1107*0a6a1f1dSLionel Sambuc A a1{1,2};
1108*0a6a1f1dSLionel Sambuc A a2{a2.i1 + 2}; // expected-warning{{uninitialized}}
1109*0a6a1f1dSLionel Sambuc A a3 = {a3.i1 + 2}; // expected-warning{{uninitialized}}
1110*0a6a1f1dSLionel Sambuc A a4 = A{a4.i2 + 2}; // expected-warning{{uninitialized}}
1111*0a6a1f1dSLionel Sambuc
1112*0a6a1f1dSLionel Sambuc B b1 = { {}, {} };
1113*0a6a1f1dSLionel Sambuc B b2 = { {}, b2.a1 };
1114*0a6a1f1dSLionel Sambuc B b3 = { b3.a1 }; // expected-warning{{uninitialized}}
1115*0a6a1f1dSLionel Sambuc B b4 = { {}, b4.a2} ; // expected-warning{{uninitialized}}
1116*0a6a1f1dSLionel Sambuc B b5 = { b5.a2 }; // expected-warning{{uninitialized}}
1117*0a6a1f1dSLionel Sambuc
1118*0a6a1f1dSLionel Sambuc B b6 = { {b6.a1.i1} }; // expected-warning{{uninitialized}}
1119*0a6a1f1dSLionel Sambuc B b7 = { {0, b7.a1.i1} };
1120*0a6a1f1dSLionel Sambuc B b8 = { {}, {b8.a1.i1} };
1121*0a6a1f1dSLionel Sambuc B b9 = { {}, {0, b9.a1.i1} };
1122*0a6a1f1dSLionel Sambuc
1123*0a6a1f1dSLionel Sambuc B b10 = { {b10.a1.i2} }; // expected-warning{{uninitialized}}
1124*0a6a1f1dSLionel Sambuc B b11 = { {0, b11.a1.i2} }; // expected-warning{{uninitialized}}
1125*0a6a1f1dSLionel Sambuc B b12 = { {}, {b12.a1.i2} };
1126*0a6a1f1dSLionel Sambuc B b13 = { {}, {0, b13.a1.i2} };
1127*0a6a1f1dSLionel Sambuc
1128*0a6a1f1dSLionel Sambuc B b14 = { {b14.a2.i1} }; // expected-warning{{uninitialized}}
1129*0a6a1f1dSLionel Sambuc B b15 = { {0, b15.a2.i1} }; // expected-warning{{uninitialized}}
1130*0a6a1f1dSLionel Sambuc B b16 = { {}, {b16.a2.i1} }; // expected-warning{{uninitialized}}
1131*0a6a1f1dSLionel Sambuc B b17 = { {}, {0, b17.a2.i1} };
1132*0a6a1f1dSLionel Sambuc
1133*0a6a1f1dSLionel Sambuc B b18 = { {b18.a2.i2} }; // expected-warning{{uninitialized}}
1134*0a6a1f1dSLionel Sambuc B b19 = { {0, b19.a2.i2} }; // expected-warning{{uninitialized}}
1135*0a6a1f1dSLionel Sambuc B b20 = { {}, {b20.a2.i2} }; // expected-warning{{uninitialized}}
1136*0a6a1f1dSLionel Sambuc B b21 = { {}, {0, b21.a2.i2} }; // expected-warning{{uninitialized}}
1137*0a6a1f1dSLionel Sambuc
1138*0a6a1f1dSLionel Sambuc B b22 = { {b18.a2.i2 + 5} };
1139*0a6a1f1dSLionel Sambuc
1140*0a6a1f1dSLionel Sambuc struct C {int a; int& b; int c; };
1141*0a6a1f1dSLionel Sambuc C c1 = { 0, num, 0 };
1142*0a6a1f1dSLionel Sambuc C c2 = { 1, num, c2.b };
1143*0a6a1f1dSLionel Sambuc C c3 = { c3.b, num }; // expected-warning{{uninitialized}}
1144*0a6a1f1dSLionel Sambuc C c4 = { 0, c4.b, 0 }; // expected-warning{{uninitialized}}
1145*0a6a1f1dSLionel Sambuc C c5 = { 0, c5.c, 0 };
1146*0a6a1f1dSLionel Sambuc C c6 = { c6.b, num, 0 }; // expected-warning{{uninitialized}}
1147*0a6a1f1dSLionel Sambuc C c7 = { 0, c7.a, 0 };
1148*0a6a1f1dSLionel Sambuc
1149*0a6a1f1dSLionel Sambuc struct D {int &a; int &b; };
1150*0a6a1f1dSLionel Sambuc D d1 = { num, num };
1151*0a6a1f1dSLionel Sambuc D d2 = { num, d2.a };
1152*0a6a1f1dSLionel Sambuc D d3 = { d3.b, num }; // expected-warning{{uninitialized}}
1153*0a6a1f1dSLionel Sambuc
1154*0a6a1f1dSLionel Sambuc // Same as above in member initializer form.
1155*0a6a1f1dSLionel Sambuc struct Awrapper {
1156*0a6a1f1dSLionel Sambuc A a1{1,2};
1157*0a6a1f1dSLionel Sambuc A a2{a2.i1 + 2}; // expected-warning{{uninitialized}}
1158*0a6a1f1dSLionel Sambuc A a3 = {a3.i1 + 2}; // expected-warning{{uninitialized}}
1159*0a6a1f1dSLionel Sambuc A a4 = A{a4.i2 + 2}; // expected-warning{{uninitialized}}
Awrapperinit_list::Awrapper1160*0a6a1f1dSLionel Sambuc Awrapper() {} // expected-note 3{{in this constructor}}
Awrapperinit_list::Awrapper1161*0a6a1f1dSLionel Sambuc Awrapper(int) :
1162*0a6a1f1dSLionel Sambuc a1{1,2},
1163*0a6a1f1dSLionel Sambuc a2{a2.i1 + 2}, // expected-warning{{uninitialized}}
1164*0a6a1f1dSLionel Sambuc a3{a3.i1 + 2}, // expected-warning{{uninitialized}}
1165*0a6a1f1dSLionel Sambuc a4{a4.i2 + 2} // expected-warning{{uninitialized}}
1166*0a6a1f1dSLionel Sambuc {}
1167*0a6a1f1dSLionel Sambuc };
1168*0a6a1f1dSLionel Sambuc
1169*0a6a1f1dSLionel Sambuc struct Bwrapper {
1170*0a6a1f1dSLionel Sambuc B b1 = { {}, {} };
1171*0a6a1f1dSLionel Sambuc B b2 = { {}, b2.a1 };
1172*0a6a1f1dSLionel Sambuc B b3 = { b3.a1 }; // expected-warning{{uninitialized}}
1173*0a6a1f1dSLionel Sambuc B b4 = { {}, b4.a2} ; // expected-warning{{uninitialized}}
1174*0a6a1f1dSLionel Sambuc B b5 = { b5.a2 }; // expected-warning{{uninitialized}}
1175*0a6a1f1dSLionel Sambuc
1176*0a6a1f1dSLionel Sambuc B b6 = { {b6.a1.i1} }; // expected-warning{{uninitialized}}
1177*0a6a1f1dSLionel Sambuc B b7 = { {0, b7.a1.i1} };
1178*0a6a1f1dSLionel Sambuc B b8 = { {}, {b8.a1.i1} };
1179*0a6a1f1dSLionel Sambuc B b9 = { {}, {0, b9.a1.i1} };
1180*0a6a1f1dSLionel Sambuc
1181*0a6a1f1dSLionel Sambuc B b10 = { {b10.a1.i2} }; // expected-warning{{uninitialized}}
1182*0a6a1f1dSLionel Sambuc B b11 = { {0, b11.a1.i2} }; // expected-warning{{uninitialized}}
1183*0a6a1f1dSLionel Sambuc B b12 = { {}, {b12.a1.i2} };
1184*0a6a1f1dSLionel Sambuc B b13 = { {}, {0, b13.a1.i2} };
1185*0a6a1f1dSLionel Sambuc
1186*0a6a1f1dSLionel Sambuc B b14 = { {b14.a2.i1} }; // expected-warning{{uninitialized}}
1187*0a6a1f1dSLionel Sambuc B b15 = { {0, b15.a2.i1} }; // expected-warning{{uninitialized}}
1188*0a6a1f1dSLionel Sambuc B b16 = { {}, {b16.a2.i1} }; // expected-warning{{uninitialized}}
1189*0a6a1f1dSLionel Sambuc B b17 = { {}, {0, b17.a2.i1} };
1190*0a6a1f1dSLionel Sambuc
1191*0a6a1f1dSLionel Sambuc B b18 = { {b18.a2.i2} }; // expected-warning{{uninitialized}}
1192*0a6a1f1dSLionel Sambuc B b19 = { {0, b19.a2.i2} }; // expected-warning{{uninitialized}}
1193*0a6a1f1dSLionel Sambuc B b20 = { {}, {b20.a2.i2} }; // expected-warning{{uninitialized}}
1194*0a6a1f1dSLionel Sambuc B b21 = { {}, {0, b21.a2.i2} }; // expected-warning{{uninitialized}}
1195*0a6a1f1dSLionel Sambuc
1196*0a6a1f1dSLionel Sambuc B b22 = { {b18.a2.i2 + 5} };
Bwrapperinit_list::Bwrapper1197*0a6a1f1dSLionel Sambuc Bwrapper() {} // expected-note 13{{in this constructor}}
Bwrapperinit_list::Bwrapper1198*0a6a1f1dSLionel Sambuc Bwrapper(int) :
1199*0a6a1f1dSLionel Sambuc b1{ {}, {} },
1200*0a6a1f1dSLionel Sambuc b2{ {}, b2.a1 },
1201*0a6a1f1dSLionel Sambuc b3{ b3.a1 }, // expected-warning{{uninitialized}}
1202*0a6a1f1dSLionel Sambuc b4{ {}, b4.a2}, // expected-warning{{uninitialized}}
1203*0a6a1f1dSLionel Sambuc b5{ b5.a2 }, // expected-warning{{uninitialized}}
1204*0a6a1f1dSLionel Sambuc
1205*0a6a1f1dSLionel Sambuc b6{ {b6.a1.i1} }, // expected-warning{{uninitialized}}
1206*0a6a1f1dSLionel Sambuc b7{ {0, b7.a1.i1} },
1207*0a6a1f1dSLionel Sambuc b8{ {}, {b8.a1.i1} },
1208*0a6a1f1dSLionel Sambuc b9{ {}, {0, b9.a1.i1} },
1209*0a6a1f1dSLionel Sambuc
1210*0a6a1f1dSLionel Sambuc b10{ {b10.a1.i2} }, // expected-warning{{uninitialized}}
1211*0a6a1f1dSLionel Sambuc b11{ {0, b11.a1.i2} }, // expected-warning{{uninitialized}}
1212*0a6a1f1dSLionel Sambuc b12{ {}, {b12.a1.i2} },
1213*0a6a1f1dSLionel Sambuc b13{ {}, {0, b13.a1.i2} },
1214*0a6a1f1dSLionel Sambuc
1215*0a6a1f1dSLionel Sambuc b14{ {b14.a2.i1} }, // expected-warning{{uninitialized}}
1216*0a6a1f1dSLionel Sambuc b15{ {0, b15.a2.i1} }, // expected-warning{{uninitialized}}
1217*0a6a1f1dSLionel Sambuc b16{ {}, {b16.a2.i1} }, // expected-warning{{uninitialized}}
1218*0a6a1f1dSLionel Sambuc b17{ {}, {0, b17.a2.i1} },
1219*0a6a1f1dSLionel Sambuc
1220*0a6a1f1dSLionel Sambuc b18{ {b18.a2.i2} }, // expected-warning{{uninitialized}}
1221*0a6a1f1dSLionel Sambuc b19{ {0, b19.a2.i2} }, // expected-warning{{uninitialized}}
1222*0a6a1f1dSLionel Sambuc b20{ {}, {b20.a2.i2} }, // expected-warning{{uninitialized}}
1223*0a6a1f1dSLionel Sambuc b21{ {}, {0, b21.a2.i2} }, // expected-warning{{uninitialized}}
1224*0a6a1f1dSLionel Sambuc
1225*0a6a1f1dSLionel Sambuc b22{ {b18.a2.i2 + 5} }
1226*0a6a1f1dSLionel Sambuc {}
1227*0a6a1f1dSLionel Sambuc };
1228*0a6a1f1dSLionel Sambuc
1229*0a6a1f1dSLionel Sambuc struct Cwrapper {
1230*0a6a1f1dSLionel Sambuc C c1 = { 0, num, 0 };
1231*0a6a1f1dSLionel Sambuc C c2 = { 1, num, c2.b };
1232*0a6a1f1dSLionel Sambuc C c3 = { c3.b, num }; // expected-warning{{uninitialized}}
1233*0a6a1f1dSLionel Sambuc C c4 = { 0, c4.b, 0 }; // expected-warning{{uninitialized}}
1234*0a6a1f1dSLionel Sambuc C c5 = { 0, c5.c, 0 };
1235*0a6a1f1dSLionel Sambuc C c6 = { c6.b, num, 0 }; // expected-warning{{uninitialized}}
1236*0a6a1f1dSLionel Sambuc C c7 = { 0, c7.a, 0 };
1237*0a6a1f1dSLionel Sambuc
Cwrapperinit_list::Cwrapper1238*0a6a1f1dSLionel Sambuc Cwrapper() {} // expected-note 3{{in this constructor}}
Cwrapperinit_list::Cwrapper1239*0a6a1f1dSLionel Sambuc Cwrapper(int) :
1240*0a6a1f1dSLionel Sambuc c1{ 0, num, 0 },
1241*0a6a1f1dSLionel Sambuc c2{ 1, num, c2.b },
1242*0a6a1f1dSLionel Sambuc c3{ c3.b, num }, // expected-warning{{uninitialized}}
1243*0a6a1f1dSLionel Sambuc c4{ 0, c4.b, 0 }, // expected-warning{{uninitialized}}
1244*0a6a1f1dSLionel Sambuc c5{ 0, c5.c, 0 },
1245*0a6a1f1dSLionel Sambuc c6{ c6.b, num, 0 }, // expected-warning{{uninitialized}}
1246*0a6a1f1dSLionel Sambuc c7{ 0, c7.a, 0 }
1247*0a6a1f1dSLionel Sambuc {}
1248*0a6a1f1dSLionel Sambuc };
1249*0a6a1f1dSLionel Sambuc
1250*0a6a1f1dSLionel Sambuc struct Dwrapper {
1251*0a6a1f1dSLionel Sambuc D d1 = { num, num };
1252*0a6a1f1dSLionel Sambuc D d2 = { num, d2.a };
1253*0a6a1f1dSLionel Sambuc D d3 = { d3.b, num }; // expected-warning{{uninitialized}}
Dwrapperinit_list::Dwrapper1254*0a6a1f1dSLionel Sambuc Dwrapper() {} // expected-note{{in this constructor}}
Dwrapperinit_list::Dwrapper1255*0a6a1f1dSLionel Sambuc Dwrapper(int) :
1256*0a6a1f1dSLionel Sambuc d1{ num, num },
1257*0a6a1f1dSLionel Sambuc d2{ num, d2.a },
1258*0a6a1f1dSLionel Sambuc d3{ d3.b, num } // expected-warning{{uninitialized}}
1259*0a6a1f1dSLionel Sambuc {}
1260*0a6a1f1dSLionel Sambuc };
1261*0a6a1f1dSLionel Sambuc }
1262*0a6a1f1dSLionel Sambuc
1263*0a6a1f1dSLionel Sambuc namespace template_class {
1264*0a6a1f1dSLionel Sambuc class Foo {
1265*0a6a1f1dSLionel Sambuc public:
Create()1266*0a6a1f1dSLionel Sambuc int *Create() { return nullptr; }
1267*0a6a1f1dSLionel Sambuc };
1268*0a6a1f1dSLionel Sambuc
1269*0a6a1f1dSLionel Sambuc template <typename T>
1270*0a6a1f1dSLionel Sambuc class A {
1271*0a6a1f1dSLionel Sambuc public:
1272*0a6a1f1dSLionel Sambuc // Don't warn on foo here.
A()1273*0a6a1f1dSLionel Sambuc A() : ptr(foo->Create()) {}
1274*0a6a1f1dSLionel Sambuc
1275*0a6a1f1dSLionel Sambuc private:
1276*0a6a1f1dSLionel Sambuc Foo *foo = new Foo;
1277*0a6a1f1dSLionel Sambuc int *ptr;
1278*0a6a1f1dSLionel Sambuc };
1279*0a6a1f1dSLionel Sambuc
1280*0a6a1f1dSLionel Sambuc template <typename T>
1281*0a6a1f1dSLionel Sambuc class B {
1282*0a6a1f1dSLionel Sambuc public:
1283*0a6a1f1dSLionel Sambuc // foo is uninitialized here, but class B is never instantiated.
B()1284*0a6a1f1dSLionel Sambuc B() : ptr(foo->Create()) {}
1285*0a6a1f1dSLionel Sambuc
1286*0a6a1f1dSLionel Sambuc private:
1287*0a6a1f1dSLionel Sambuc Foo *foo;
1288*0a6a1f1dSLionel Sambuc int *ptr;
1289*0a6a1f1dSLionel Sambuc };
1290*0a6a1f1dSLionel Sambuc
1291*0a6a1f1dSLionel Sambuc template <typename T>
1292*0a6a1f1dSLionel Sambuc class C {
1293*0a6a1f1dSLionel Sambuc public:
C()1294*0a6a1f1dSLionel Sambuc C() : ptr(foo->Create()) {}
1295*0a6a1f1dSLionel Sambuc // expected-warning@-1 {{field 'foo' is uninitialized when used here}}
1296*0a6a1f1dSLionel Sambuc private:
1297*0a6a1f1dSLionel Sambuc Foo *foo;
1298*0a6a1f1dSLionel Sambuc int *ptr;
1299*0a6a1f1dSLionel Sambuc };
1300*0a6a1f1dSLionel Sambuc
1301*0a6a1f1dSLionel Sambuc C<int> c;
1302*0a6a1f1dSLionel Sambuc // expected-note@-1 {{in instantiation of member function 'template_class::C<int>::C' requested here}}
1303*0a6a1f1dSLionel Sambuc
1304*0a6a1f1dSLionel Sambuc }
1305*0a6a1f1dSLionel Sambuc
1306*0a6a1f1dSLionel Sambuc namespace base_class_access {
1307*0a6a1f1dSLionel Sambuc struct A {
1308*0a6a1f1dSLionel Sambuc A();
1309*0a6a1f1dSLionel Sambuc A(int);
1310*0a6a1f1dSLionel Sambuc
1311*0a6a1f1dSLionel Sambuc int i;
1312*0a6a1f1dSLionel Sambuc int foo();
1313*0a6a1f1dSLionel Sambuc
1314*0a6a1f1dSLionel Sambuc static int bar();
1315*0a6a1f1dSLionel Sambuc };
1316*0a6a1f1dSLionel Sambuc
1317*0a6a1f1dSLionel Sambuc struct B : public A {
Bbase_class_access::B1318*0a6a1f1dSLionel Sambuc B(int (*)[1]) : A() {}
Bbase_class_access::B1319*0a6a1f1dSLionel Sambuc B(int (*)[2]) : A(bar()) {}
1320*0a6a1f1dSLionel Sambuc
Bbase_class_access::B1321*0a6a1f1dSLionel Sambuc B(int (*)[3]) : A(i) {}
1322*0a6a1f1dSLionel Sambuc // expected-warning@-1 {{base class 'base_class_access::A' is uninitialized when used here to access 'base_class_access::A::i'}}
1323*0a6a1f1dSLionel Sambuc
Bbase_class_access::B1324*0a6a1f1dSLionel Sambuc B(int (*)[4]) : A(foo()) {}
1325*0a6a1f1dSLionel Sambuc // expected-warning@-1 {{base_class_access::A' is uninitialized when used here to access 'base_class_access::A::foo'}}
1326*0a6a1f1dSLionel Sambuc };
1327*0a6a1f1dSLionel Sambuc
1328*0a6a1f1dSLionel Sambuc struct C {
Cbase_class_access::C1329*0a6a1f1dSLionel Sambuc C(int) {}
1330*0a6a1f1dSLionel Sambuc };
1331*0a6a1f1dSLionel Sambuc
1332*0a6a1f1dSLionel Sambuc struct D : public C, public A {
Dbase_class_access::D1333*0a6a1f1dSLionel Sambuc D(int (*)[1]) : C(0) {}
Dbase_class_access::D1334*0a6a1f1dSLionel Sambuc D(int (*)[2]) : C(bar()) {}
1335*0a6a1f1dSLionel Sambuc
Dbase_class_access::D1336*0a6a1f1dSLionel Sambuc D(int (*)[3]) : C(i) {}
1337*0a6a1f1dSLionel Sambuc // expected-warning@-1 {{base class 'base_class_access::A' is uninitialized when used here to access 'base_class_access::A::i'}}
1338*0a6a1f1dSLionel Sambuc
Dbase_class_access::D1339*0a6a1f1dSLionel Sambuc D(int (*)[4]) : C(foo()) {}
1340*0a6a1f1dSLionel Sambuc // expected-warning@-1 {{base_class_access::A' is uninitialized when used here to access 'base_class_access::A::foo'}}
1341*0a6a1f1dSLionel Sambuc };
1342*0a6a1f1dSLionel Sambuc
1343*0a6a1f1dSLionel Sambuc }
1344*0a6a1f1dSLionel Sambuc
1345*0a6a1f1dSLionel Sambuc namespace value {
1346*0a6a1f1dSLionel Sambuc template <class T> T move(T t);
1347*0a6a1f1dSLionel Sambuc template <class T> T notmove(T t);
1348*0a6a1f1dSLionel Sambuc }
1349*0a6a1f1dSLionel Sambuc namespace lvalueref {
1350*0a6a1f1dSLionel Sambuc template <class T> T move(T& t);
1351*0a6a1f1dSLionel Sambuc template <class T> T notmove(T& t);
1352*0a6a1f1dSLionel Sambuc }
1353*0a6a1f1dSLionel Sambuc namespace rvalueref {
1354*0a6a1f1dSLionel Sambuc template <class T> T move(T&& t);
1355*0a6a1f1dSLionel Sambuc template <class T> T notmove(T&& t);
1356*0a6a1f1dSLionel Sambuc }
1357*0a6a1f1dSLionel Sambuc
1358*0a6a1f1dSLionel Sambuc namespace move_test {
1359*0a6a1f1dSLionel Sambuc int a1 = std::move(a1); // expected-warning {{uninitialized}}
1360*0a6a1f1dSLionel Sambuc int a2 = value::move(a2); // expected-warning {{uninitialized}}
1361*0a6a1f1dSLionel Sambuc int a3 = value::notmove(a3); // expected-warning {{uninitialized}}
1362*0a6a1f1dSLionel Sambuc int a4 = lvalueref::move(a4);
1363*0a6a1f1dSLionel Sambuc int a5 = lvalueref::notmove(a5);
1364*0a6a1f1dSLionel Sambuc int a6 = rvalueref::move(a6);
1365*0a6a1f1dSLionel Sambuc int a7 = rvalueref::notmove(a7);
1366*0a6a1f1dSLionel Sambuc
test()1367*0a6a1f1dSLionel Sambuc void test() {
1368*0a6a1f1dSLionel Sambuc int a1 = std::move(a1); // expected-warning {{uninitialized}}
1369*0a6a1f1dSLionel Sambuc int a2 = value::move(a2); // expected-warning {{uninitialized}}
1370*0a6a1f1dSLionel Sambuc int a3 = value::notmove(a3); // expected-warning {{uninitialized}}
1371*0a6a1f1dSLionel Sambuc int a4 = lvalueref::move(a4);
1372*0a6a1f1dSLionel Sambuc int a5 = lvalueref::notmove(a5);
1373*0a6a1f1dSLionel Sambuc int a6 = rvalueref::move(a6);
1374*0a6a1f1dSLionel Sambuc int a7 = rvalueref::notmove(a7);
1375*0a6a1f1dSLionel Sambuc }
1376*0a6a1f1dSLionel Sambuc
1377*0a6a1f1dSLionel Sambuc class A {
1378*0a6a1f1dSLionel Sambuc int a;
A(int (*)[1])1379*0a6a1f1dSLionel Sambuc A(int (*) [1]) : a(std::move(a)) {} // expected-warning {{uninitialized}}
A(int (*)[2])1380*0a6a1f1dSLionel Sambuc A(int (*) [2]) : a(value::move(a)) {} // expected-warning {{uninitialized}}
A(int (*)[3])1381*0a6a1f1dSLionel Sambuc A(int (*) [3]) : a(value::notmove(a)) {} // expected-warning {{uninitialized}}
A(int (*)[4])1382*0a6a1f1dSLionel Sambuc A(int (*) [4]) : a(lvalueref::move(a)) {}
A(int (*)[5])1383*0a6a1f1dSLionel Sambuc A(int (*) [5]) : a(lvalueref::notmove(a)) {}
A(int (*)[6])1384*0a6a1f1dSLionel Sambuc A(int (*) [6]) : a(rvalueref::move(a)) {}
A(int (*)[7])1385*0a6a1f1dSLionel Sambuc A(int (*) [7]) : a(rvalueref::notmove(a)) {}
1386*0a6a1f1dSLionel Sambuc };
1387*0a6a1f1dSLionel Sambuc }
1388