• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -Wall -Wuninitialized -Wno-unused-value -std=c++11 -verify %s
2 
3 // definitions for std::move
4 namespace std {
5 inline namespace foo {
6 template <class T> struct remove_reference { typedef T type; };
7 template <class T> struct remove_reference<T&> { typedef T type; };
8 template <class T> struct remove_reference<T&&> { typedef T type; };
9 
10 template <class T> typename remove_reference<T>::type&& move(T&& t);
11 }
12 }
13 
14 int foo(int x);
15 int bar(int* x);
16 int boo(int& x);
17 int far(const int& x);
18 int moved(int&& x);
19 int &ref(int x);
20 
21 // Test self-references within initializers which are guaranteed to be
22 // uninitialized.
23 int a = a; // no-warning: used to signal intended lack of initialization.
24 int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
25 int c = (c + c); // expected-warning 2 {{variable 'c' is uninitialized when used within its own initialization}}
26 int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
27 int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
28 
29 // Thes don't warn as they don't require the value.
30 int g = sizeof(g);
31 void* ptr = &ptr;
32 int h = bar(&h);
33 int i = boo(i);
34 int j = far(j);
35 int k = __alignof__(k);
36 
37 int l = k ? l : l;  // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}}
38 int m = 1 + (k ? m : m);  // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}}
39 int n = -n;  // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
40 int o = std::move(o); // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
41 const int p = std::move(p); // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
42 int q = moved(std::move(q)); // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
43 int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
44 int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
45 int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
46 int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
47 int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
48 int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
49 int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
50 int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
51 int z = ++ref(z); // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
52 int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
53 int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
54 
test_stuff()55 void test_stuff () {
56   int a = a; // no-warning: used to signal intended lack of initialization.
57   int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
58   int c = (c + c); // expected-warning {{variable 'c' is uninitialized when used within its own initialization}}
59   int d = ({ d + d ;}); // expected-warning {{variable 'd' is uninitialized when used within its own initialization}}
60   int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
61   int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
62 
63   // Thes don't warn as they don't require the value.
64   int g = sizeof(g);
65   void* ptr = &ptr;
66   int h = bar(&h);
67   int i = boo(i);
68   int j = far(j);
69   int k = __alignof__(k);
70 
71   int l = k ? l : l;  // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
72   int m = 1 + (k ? m : m);  // expected-warning {{'m' is uninitialized when used within its own initialization}}
73   int n = -n;  // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
74   int o = std::move(o);  // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
75   const int p = std::move(p);  // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
76   int q = moved(std::move(q));  // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
77   int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
78   int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
79   int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
80   int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
81   int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
82   int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
83   int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
84   int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
85   int z = ++ref(z);                              // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
86   int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
87   int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
88 
89   for (;;) {
90     int a = a; // no-warning: used to signal intended lack of initialization.
91     int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
92     int c = (c + c); // expected-warning {{variable 'c' is uninitialized when used within its own initialization}}
93     int d = ({ d + d ;}); // expected-warning {{variable 'd' is uninitialized when used within its own initialization}}
94     int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
95     int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
96 
97     // Thes don't warn as they don't require the value.
98     int g = sizeof(g);
99     void* ptr = &ptr;
100     int h = bar(&h);
101     int i = boo(i);
102     int j = far(j);
103     int k = __alignof__(k);
104 
105     int l = k ? l : l;  // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
106     int m = 1 + (k ? m : m);  // expected-warning {{'m' is uninitialized when used within its own initialization}}
107     int n = -n;  // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
108     int o = std::move(o);  // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
109     const int p = std::move(p);  // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
110     int q = moved(std::move(q));  // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
111     int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
112     int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
113     int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
114     int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
115     int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
116     int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
117     int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
118     int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
119     int z = ++ref(z);                              // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
120     int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
121     int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
122 
123   }
124 }
125 
test_comma()126 void test_comma() {
127   int a;  // expected-note {{initialize the variable 'a' to silence this warning}}
128   int b = (a, a ?: 2);  // expected-warning {{variable 'a' is uninitialized when used here}}
129   int c = (a, a, b, c);  // expected-warning {{variable 'c' is uninitialized when used within its own initialization}}
130   int d;  // expected-note {{initialize the variable 'd' to silence this warning}}
131   int e = (foo(d), e, b); // expected-warning {{variable 'd' is uninitialized when used here}}
132   int f;  // expected-note {{initialize the variable 'f' to silence this warning}}
133   f = f + 1, 2;  // expected-warning {{variable 'f' is uninitialized when used here}}
134   int h;
135   int g = (h, g, 2);  // no-warning: h, g are evaluated but not used.
136 }
137 
138 namespace member_ptr {
139 struct A {
140   int x;
141   int y;
Amember_ptr::A142   A(int x) : x{x} {}
143 };
144 
test_member_ptr()145 void test_member_ptr() {
146   int A::* px = &A::x;
147   A a{a.*px}; // expected-warning {{variable 'a' is uninitialized when used within its own initialization}}
148   A b = b; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
149 }
150 }
151 
152 namespace const_ptr {
153 void foo(int *a);
154 void bar(const int *a);
155 void foobar(const int **a);
156 
test_const_ptr()157 void test_const_ptr() {
158   int a;
159   int b;  // expected-note {{initialize the variable 'b' to silence this warning}}
160   foo(&a);
161   bar(&b);
162   b = a + b; // expected-warning {{variable 'b' is uninitialized when used here}}
163   int *ptr;  //expected-note {{initialize the variable 'ptr' to silence this warning}}
164   const int *ptr2;
165   foo(ptr); // expected-warning {{variable 'ptr' is uninitialized when used here}}
166   foobar(&ptr2);
167 }
168 }
169 
170 // Also test similar constructs in a field's initializer.
171 struct S {
172   int x;
173   int y;
174   const int z = 5;
175   void *ptr;
176 
SS177   S(bool (*)[1]) : x(x) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS178   S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS179   S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field 'x' is uninitialized when used here}}
SS180   S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS181   S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field 'x' is uninitialized when used here}}
182 
183   // These don't actually require the value of x and so shouldn't warn.
SS184   S(char (*)[1]) : x(sizeof(x)) {} // rdar://8610363
SS185   S(char (*)[2]) : ptr(&ptr) {}
SS186   S(char (*)[3]) : x(bar(&x)) {}
SS187   S(char (*)[4]) : x(boo(x)) {}
SS188   S(char (*)[5]) : x(far(x)) {}
SS189   S(char (*)[6]) : x(__alignof__(x)) {}
190 
SS191   S(int (*)[1]) : x(0), y(x ? y : y) {} // expected-warning 2{{field 'y' is uninitialized when used here}}
SS192   S(int (*)[2]) : x(0), y(1 + (x ? y : y)) {} // expected-warning 2{{field 'y' is uninitialized when used here}}
SS193   S(int (*)[3]) : x(-x) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS194   S(int (*)[4]) : x(std::move(x)) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS195   S(int (*)[5]) : z(std::move(z)) {} // expected-warning {{field 'z' is uninitialized when used here}}
SS196   S(int (*)[6]) : x(moved(std::move(x))) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS197   S(int (*)[7]) : x(0), y(std::move((x ? x : (18, y)))) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS198   S(int (*)[8]) : x(0), y(x ?: y) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS199   S(int (*)[9]) : x(0), y(y ?: x) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS200   S(int (*)[10]) : x(0), y((foo(y), x)) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS201   S(int (*)[11]) : x(0), y(x += y) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS202   S(int (*)[12]) : x(x += 10) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS203   S(int (*)[13]) : x(x++) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS204   S(int (*)[14]) : x(0), y(((x ? (y, x) : (77, y))++, sizeof(y))) {} // expected-warning {{field 'y' is uninitialized when used here}}
SS205   S(int (*)[15]) : x(++ref(x)) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS206   S(int (*)[16]) : x((ref(x) += 10)) {} // expected-warning {{field 'x' is uninitialized when used here}}
SS207   S(int (*)[17]) : x(0), y(y ? x : x) {} // expected-warning {{field 'y' is uninitialized when used here}}
208 };
209 
210 // Test self-references with record types.
211 class A {
212   // Non-POD class.
213   public:
214     enum count { ONE, TWO, THREE };
215     int num;
216     static int count;
get() const217     int get() const { return num; }
get2()218     int get2() { return num; }
set(int x)219     int set(int x) { num = x; return num; }
zero()220     static int zero() { return 0; }
221 
A()222     A() {}
A(A const & a)223     A(A const &a) {}
A(int x)224     A(int x) {}
A(int * x)225     A(int *x) {}
A(A * a)226     A(A *a) {}
A(A && a)227     A(A &&a) {}
228     ~A();
229     bool operator!();
230     bool operator!=(const A&);
231 };
232 
233 bool operator!=(int, const A&);
234 
getA()235 A getA() { return A(); }
getA(int x)236 A getA(int x) { return A(); }
getA(A * a)237 A getA(A* a) { return A(); }
getA(A a)238 A getA(A a) { return A(); }
moveA(A && a)239 A moveA(A&& a) { return A(); }
const_refA(const A & a)240 A const_refA(const A& a) { return A(); }
241 
setupA(bool x)242 void setupA(bool x) {
243   A a1;
244   a1.set(a1.get());
245   A a2(a1.get());
246   A a3(a1);
247   A a4(&a4);
248   A a5(a5.zero());
249   A a6(a6.ONE);
250   A a7 = getA();
251   A a8 = getA(a8.TWO);
252   A a9 = getA(&a9);
253   A a10(a10.count);
254 
255   A a11(a11);  // expected-warning {{variable 'a11' is uninitialized when used within its own initialization}}
256   A a12(a12.get());  // expected-warning {{variable 'a12' is uninitialized when used within its own initialization}}
257   A a13(a13.num);  // expected-warning {{variable 'a13' is uninitialized when used within its own initialization}}
258   A a14 = A(a14);  // expected-warning {{variable 'a14' is uninitialized when used within its own initialization}}
259   A a15 = getA(a15.num);  // expected-warning {{variable 'a15' is uninitialized when used within its own initialization}}
260   A a16(&a16.num);  // expected-warning {{variable 'a16' is uninitialized when used within its own initialization}}
261   A a17(a17.get2());  // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}}
262   A a18 = x ? a18 : a17;  // expected-warning {{variable 'a18' is uninitialized when used within its own initialization}}
263   A a19 = getA(x ? a19 : a17);  // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}}
264   A a20{a20};  // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}}
265   A a21 = {a21};  // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}}
266 
267   // FIXME: Make the local uninitialized warning consistent with the global
268   // uninitialized checking.
269   A *a22 = new A(a22->count);  // expected-warning {{variable 'a22' is uninitialized when used within its own initialization}}
270   A *a23 = new A(a23->ONE);  // expected-warning {{variable 'a23' is uninitialized when used within its own initialization}}
271   A *a24 = new A(a24->TWO);  // expected-warning {{variable 'a24' is uninitialized when used within its own initialization}}
272   A *a25 = new A(a25->zero());  // expected-warning {{variable 'a25' is uninitialized when used within its own initialization}}
273 
274   A *a26 = new A(a26->get());    // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}}
275   A *a27 = new A(a27->get2());  // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}}
276   A *a28 = new A(a28->num);  // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}}
277 
278   const A a29(a29);  // expected-warning {{variable 'a29' is uninitialized when used within its own initialization}}
279   const A a30 = a30;  // expected-warning {{variable 'a30' is uninitialized when used within its own initialization}}
280 
281   A a31 = std::move(a31);  // expected-warning {{variable 'a31' is uninitialized when used within its own initialization}}
282   A a32 = moveA(std::move(a32));  // expected-warning {{variable 'a32' is uninitialized when used within its own initialization}}
283   A a33 = A(std::move(a33));   // expected-warning {{variable 'a33' is uninitialized when used within its own initialization}}
284   A a34(std::move(a34));   // expected-warning {{variable 'a34' is uninitialized when used within its own initialization}}
285   A a35 = std::move(x ? a34 : (37, a35));  // expected-warning {{variable 'a35' is uninitialized when used within its own initialization}}
286 
287   A a36 = const_refA(a36);
288   A a37(const_refA(a37));
289 
290   A a38({a38});  // expected-warning {{variable 'a38' is uninitialized when used within its own initialization}}
291   A a39 = {a39};  // expected-warning {{variable 'a39' is uninitialized when used within its own initialization}}
292   A a40 = A({a40});  // expected-warning {{variable 'a40' is uninitialized when used within its own initialization}}
293 
294   A a41 = !a41;  // expected-warning {{variable 'a41' is uninitialized when used within its own initialization}}
295   A a42 = !(a42);  // expected-warning {{variable 'a42' is uninitialized when used within its own initialization}}
296   A a43 = a43 != a42;  // expected-warning {{variable 'a43' is uninitialized when used within its own initialization}}
297   A a44 = a43 != a44;  // expected-warning {{variable 'a44' is uninitialized when used within its own initialization}}
298   A a45 = a45 != a45;  // expected-warning 2{{variable 'a45' is uninitialized when used within its own initialization}}
299   A a46 = 0 != a46;  // expected-warning {{variable 'a46' is uninitialized when used within its own initialization}}
300 
301   A a47(a47.set(a47.num));  // expected-warning 2{{variable 'a47' is uninitialized when used within its own initialization}}
302   A a48(a47.set(a48.num));  // expected-warning {{variable 'a48' is uninitialized when used within its own initialization}}
303   A a49(a47.set(a48.num));
304 }
305 
306 bool cond;
307 
308 A a1;
309 A a2(a1.get());
310 A a3(a1);
311 A a4(&a4);
312 A a5(a5.zero());
313 A a6(a6.ONE);
314 A a7 = getA();
315 A a8 = getA(a8.TWO);
316 A a9 = getA(&a9);
317 A a10(a10.count);
318 
319 A a11(a11);  // expected-warning {{variable 'a11' is uninitialized when used within its own initialization}}
320 A a12(a12.get());  // expected-warning {{variable 'a12' is uninitialized when used within its own initialization}}
321 A a13(a13.num);  // expected-warning {{variable 'a13' is uninitialized when used within its own initialization}}
322 A a14 = A(a14);  // expected-warning {{variable 'a14' is uninitialized when used within its own initialization}}
323 A a15 = getA(a15.num);  // expected-warning {{variable 'a15' is uninitialized when used within its own initialization}}
324 A a16(&a16.num);  // expected-warning {{variable 'a16' is uninitialized when used within its own initialization}}
325 A a17(a17.get2());  // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}}
326 A a18 = cond ? a18 : a17;  // expected-warning {{variable 'a18' is uninitialized when used within its own initialization}}
327 A a19 = getA(cond ? a19 : a17);  // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}}
328 A a20{a20};  // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}}
329 A a21 = {a21};  // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}}
330 
331 A *a22 = new A(a22->count);
332 A *a23 = new A(a23->ONE);
333 A *a24 = new A(a24->TWO);
334 A *a25 = new A(a25->zero());
335 
336 A *a26 = new A(a26->get());    // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}}
337 A *a27 = new A(a27->get2());  // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}}
338 A *a28 = new A(a28->num);  // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}}
339 
340 const A a29(a29);  // expected-warning {{variable 'a29' is uninitialized when used within its own initialization}}
341 const A a30 = a30;  // expected-warning {{variable 'a30' is uninitialized when used within its own initialization}}
342 
343 A a31 = std::move(a31);  // expected-warning {{variable 'a31' is uninitialized when used within its own initialization}}
344 A a32 = moveA(std::move(a32));  // expected-warning {{variable 'a32' is uninitialized when used within its own initialization}}
345 A a33 = A(std::move(a33));   // expected-warning {{variable 'a33' is uninitialized when used within its own initialization}}
346 A a34(std::move(a34));   // expected-warning {{variable 'a34' is uninitialized when used within its own initialization}}
347 A a35 = std::move(x ? a34 : (37, a35));  // expected-warning {{variable 'a35' is uninitialized when used within its own initialization}}
348 
349 A a36 = const_refA(a36);
350 A a37(const_refA(a37));
351 
352 A a38({a38});  // expected-warning {{variable 'a38' is uninitialized when used within its own initialization}}
353 A a39 = {a39};  // expected-warning {{variable 'a39' is uninitialized when used within its own initialization}}
354 A a40 = A({a40});  // expected-warning {{variable 'a40' is uninitialized when used within its own initialization}}
355 
356 A a41 = !a41;  // expected-warning {{variable 'a41' is uninitialized when used within its own initialization}}
357 A a42 = !(a42);  // expected-warning {{variable 'a42' is uninitialized when used within its own initialization}}
358 A a43 = a43 != a42;  // expected-warning {{variable 'a43' is uninitialized when used within its own initialization}}
359 A a44 = a43 != a44;  // expected-warning {{variable 'a44' is uninitialized when used within its own initialization}}
360 A a45 = a45 != a45;  // expected-warning 2{{variable 'a45' is uninitialized when used within its own initialization}}
361 
362 A a46 = 0 != a46;  // expected-warning {{variable 'a46' is uninitialized when used within its own initialization}}
363 
364 A a47(a47.set(a47.num));  // expected-warning 2{{variable 'a47' is uninitialized when used within its own initialization}}
365 A a48(a47.set(a48.num));  // expected-warning {{variable 'a48' is uninitialized when used within its own initialization}}
366 A a49(a47.set(a48.num));
367 
368 class T {
369   A a, a2;
370   const A c_a;
371   A* ptr_a;
372 
T()373   T() {}
T(bool (*)[1])374   T(bool (*)[1]) : a() {}
T(bool (*)[2])375   T(bool (*)[2]) : a2(a.get()) {}
T(bool (*)[3])376   T(bool (*)[3]) : a2(a) {}
T(bool (*)[4])377   T(bool (*)[4]) : a(&a) {}
T(bool (*)[5])378   T(bool (*)[5]) : a(a.zero()) {}
T(bool (*)[6])379   T(bool (*)[6]) : a(a.ONE) {}
T(bool (*)[7])380   T(bool (*)[7]) : a(getA()) {}
T(bool (*)[8])381   T(bool (*)[8]) : a2(getA(a.TWO)) {}
T(bool (*)[9])382   T(bool (*)[9]) : a(getA(&a)) {}
T(bool (*)[10])383   T(bool (*)[10]) : a(a.count) {}
384 
T(bool (*)[11])385   T(bool (*)[11]) : a(a) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[12])386   T(bool (*)[12]) : a(a.get()) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[13])387   T(bool (*)[13]) : a(a.num) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[14])388   T(bool (*)[14]) : a(A(a)) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[15])389   T(bool (*)[15]) : a(getA(a.num)) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[16])390   T(bool (*)[16]) : a(&a.num) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[17])391   T(bool (*)[17]) : a(a.get2()) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[18])392   T(bool (*)[18]) : a2(cond ? a2 : a) {}  // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[19])393   T(bool (*)[19]) : a2(cond ? a2 : a) {}  // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[20])394   T(bool (*)[20]) : a{a} {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[21])395   T(bool (*)[21]) : a({a}) {}  // expected-warning {{field 'a' is uninitialized when used here}}
396 
T(bool (*)[22])397   T(bool (*)[22]) : ptr_a(new A(ptr_a->count)) {}
T(bool (*)[23])398   T(bool (*)[23]) : ptr_a(new A(ptr_a->ONE)) {}
T(bool (*)[24])399   T(bool (*)[24]) : ptr_a(new A(ptr_a->TWO)) {}
T(bool (*)[25])400   T(bool (*)[25]) : ptr_a(new A(ptr_a->zero())) {}
401 
T(bool (*)[26])402   T(bool (*)[26]) : ptr_a(new A(ptr_a->get())) {}  // expected-warning {{field 'ptr_a' is uninitialized when used here}}
T(bool (*)[27])403   T(bool (*)[27]) : ptr_a(new A(ptr_a->get2())) {}  // expected-warning {{field 'ptr_a' is uninitialized when used here}}
T(bool (*)[28])404   T(bool (*)[28]) : ptr_a(new A(ptr_a->num)) {}  // expected-warning {{field 'ptr_a' is uninitialized when used here}}
405 
T(bool (*)[29])406   T(bool (*)[29]) : c_a(c_a) {}  // expected-warning {{field 'c_a' is uninitialized when used here}}
T(bool (*)[30])407   T(bool (*)[30]) : c_a(A(c_a)) {}  // expected-warning {{field 'c_a' is uninitialized when used here}}
408 
T(bool (*)[31])409   T(bool (*)[31]) : a(std::move(a)) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[32])410   T(bool (*)[32]) : a(moveA(std::move(a))) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[33])411   T(bool (*)[33]) : a(A(std::move(a))) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[34])412   T(bool (*)[34]) : a(A(std::move(a))) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[35])413   T(bool (*)[35]) : a2(std::move(x ? a : (37, a2))) {}  // expected-warning {{field 'a2' is uninitialized when used here}}
414 
T(bool (*)[36])415   T(bool (*)[36]) : a(const_refA(a)) {}
T(bool (*)[37])416   T(bool (*)[37]) : a(A(const_refA(a))) {}
417 
T(bool (*)[38])418   T(bool (*)[38]) : a({a}) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[39])419   T(bool (*)[39]) : a{a} {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[40])420   T(bool (*)[40]) : a({a}) {}  // expected-warning {{field 'a' is uninitialized when used here}}
421 
T(bool (*)[41])422   T(bool (*)[41]) : a(!a) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[42])423   T(bool (*)[42]) : a(!(a)) {}  // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[43])424   T(bool (*)[43]) : a(), a2(a2 != a) {}  // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[44])425   T(bool (*)[44]) : a(), a2(a != a2) {}  // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[45])426   T(bool (*)[45]) : a(a != a) {}  // expected-warning 2{{field 'a' is uninitialized when used here}}
T(bool (*)[46])427   T(bool (*)[46]) : a(0 != a) {}  // expected-warning {{field 'a' is uninitialized when used here}}
428 
T(bool (*)[47])429   T(bool (*)[47]) : a2(a2.set(a2.num)) {}  // expected-warning 2{{field 'a2' is uninitialized when used here}}
T(bool (*)[48])430   T(bool (*)[48]) : a2(a.set(a2.num)) {}  // expected-warning {{field 'a2' is uninitialized when used here}}
T(bool (*)[49])431   T(bool (*)[49]) : a2(a.set(a.num)) {}
432 
433 };
434 
435 struct B {
436   // POD struct.
437   int x;
438   int *y;
439 };
440 
getB()441 B getB() { return B(); };
getB(int x)442 B getB(int x) { return B(); };
getB(int * x)443 B getB(int *x) { return B(); };
getB(B * b)444 B getB(B *b) { return B(); };
moveB(B && b)445 B moveB(B &&b) { return B(); };
446 
getPtrB()447 B* getPtrB() { return 0; };
getPtrB(int x)448 B* getPtrB(int x) { return 0; };
getPtrB(int * x)449 B* getPtrB(int *x) { return 0; };
getPtrB(B ** b)450 B* getPtrB(B **b) { return 0; };
451 
setupB(bool x)452 void setupB(bool x) {
453   B b1;
454   B b2(b1);
455   B b3 = { 5, &b3.x };
456   B b4 = getB();
457   B b5 = getB(&b5);
458   B b6 = getB(&b6.x);
459 
460   // Silence unused warning
461   (void) b2;
462   (void) b4;
463 
464   B b7(b7);  // expected-warning {{variable 'b7' is uninitialized when used within its own initialization}}
465   B b8 = getB(b8.x);  // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}}
466   B b9 = getB(b9.y);  // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}}
467   B b10 = getB(-b10.x);  // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}}
468 
469   B* b11 = 0;
470   B* b12(b11);
471   B* b13 = getPtrB();
472   B* b14 = getPtrB(&b14);
473 
474   (void) b12;
475   (void) b13;
476 
477   B* b15 = getPtrB(b15->x);  // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}}
478   B* b16 = getPtrB(b16->y);  // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}}
479 
480   B b17 = { b17.x = 5, b17.y = 0 };
481   B b18 = { b18.x + 1, b18.y };  // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}}
482 
483   const B b19 = b19;  // expected-warning {{variable 'b19' is uninitialized when used within its own initialization}}
484   const B b20(b20);  // expected-warning {{variable 'b20' is uninitialized when used within its own initialization}}
485 
486   B b21 = std::move(b21);  // expected-warning {{variable 'b21' is uninitialized when used within its own initialization}}
487   B b22 = moveB(std::move(b22));  // expected-warning {{variable 'b22' is uninitialized when used within its own initialization}}
488   B b23 = B(std::move(b23));   // expected-warning {{variable 'b23' is uninitialized when used within its own initialization}}
489   B b24 = std::move(x ? b23 : (18, b24));  // expected-warning {{variable 'b24' is uninitialized when used within its own initialization}}
490 }
491 
492 B b1;
493 B b2(b1);
494 B b3 = { 5, &b3.x };
495 B b4 = getB();
496 B b5 = getB(&b5);
497 B b6 = getB(&b6.x);
498 
499 B b7(b7);  // expected-warning {{variable 'b7' is uninitialized when used within its own initialization}}
500 B b8 = getB(b8.x);  // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}}
501 B b9 = getB(b9.y);  // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}}
502 B b10 = getB(-b10.x);  // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}}
503 
504 B* b11 = 0;
505 B* b12(b11);
506 B* b13 = getPtrB();
507 B* b14 = getPtrB(&b14);
508 
509 B* b15 = getPtrB(b15->x);  // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}}
510 B* b16 = getPtrB(b16->y);  // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}}
511 
512 B b17 = { b17.x = 5, b17.y = 0 };
513 B b18 = { b18.x + 1, b18.y };  // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}}
514 
515 const B b19 = b19;  // expected-warning {{variable 'b19' is uninitialized when used within its own initialization}}
516 const B b20(b20);  // expected-warning {{variable 'b20' is uninitialized when used within its own initialization}}
517 
518 B b21 = std::move(b21);  // expected-warning {{variable 'b21' is uninitialized when used within its own initialization}}
519 B b22 = moveB(std::move(b22));  // expected-warning {{variable 'b22' is uninitialized when used within its own initialization}}
520 B b23 = B(std::move(b23));   // expected-warning {{variable 'b23' is uninitialized when used within its own initialization}}
521 B b24 = std::move(x ? b23 : (18, b24));  // expected-warning {{variable 'b24' is uninitialized when used within its own initialization}}
522 
523 class U {
524   B b1, b2;
525   B *ptr1, *ptr2;
526   const B constb = {};
527 
U()528   U() {}
U(bool (*)[1])529   U(bool (*)[1]) : b1() {}
U(bool (*)[2])530   U(bool (*)[2]) : b2(b1) {}
U(bool (*)[3])531   U(bool (*)[3]) : b1{ 5, &b1.x } {}
U(bool (*)[4])532   U(bool (*)[4]) : b1(getB()) {}
U(bool (*)[5])533   U(bool (*)[5]) : b1(getB(&b1)) {}
U(bool (*)[6])534   U(bool (*)[6]) : b1(getB(&b1.x)) {}
535 
U(bool (*)[7])536   U(bool (*)[7]) : b1(b1) {}  // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[8])537   U(bool (*)[8]) : b1(getB(b1.x)) {}  // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[9])538   U(bool (*)[9]) : b1(getB(b1.y)) {}  // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[10])539   U(bool (*)[10]) : b1(getB(-b1.x)) {}  // expected-warning {{field 'b1' is uninitialized when used here}}
540 
U(bool (*)[11])541   U(bool (*)[11]) : ptr1(0) {}
U(bool (*)[12])542   U(bool (*)[12]) : ptr1(0), ptr2(ptr1) {}
U(bool (*)[13])543   U(bool (*)[13]) : ptr1(getPtrB()) {}
U(bool (*)[14])544   U(bool (*)[14]) : ptr1(getPtrB(&ptr1)) {}
545 
U(bool (*)[15])546   U(bool (*)[15]) : ptr1(getPtrB(ptr1->x)) {}  // expected-warning {{field 'ptr1' is uninitialized when used here}}
U(bool (*)[16])547   U(bool (*)[16]) : ptr2(getPtrB(ptr2->y)) {}  // expected-warning {{field 'ptr2' is uninitialized when used here}}
548 
U(bool (*)[17])549   U(bool (*)[17]) : b1 { b1.x = 5, b1.y = 0 } {}
U(bool (*)[18])550   U(bool (*)[18]) : b1 { b1.x + 1, b1.y } {}  // expected-warning 2{{field 'b1' is uninitialized when used here}}
551 
U(bool (*)[19])552   U(bool (*)[19]) : constb(constb) {}  // expected-warning {{field 'constb' is uninitialized when used here}}
U(bool (*)[20])553   U(bool (*)[20]) : constb(B(constb)) {}  // expected-warning {{field 'constb' is uninitialized when used here}}
554 
U(bool (*)[21])555   U(bool (*)[21]) : b1(std::move(b1)) {}  // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[22])556   U(bool (*)[22]) : b1(moveB(std::move(b1))) {}  // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[23])557   U(bool (*)[23]) : b1(B(std::move(b1))) {}  // expected-warning {{field 'b1' is uninitialized when used here}}
U(bool (*)[24])558   U(bool (*)[24]) : b2(std::move(x ? b1 : (18, b2))) {}  // expected-warning {{field 'b2' is uninitialized when used here}}
559 };
560 
561 struct C { char a[100], *e; } car = { .e = car.a };
562 
563 // <rdar://problem/10398199>
564 namespace rdar10398199 {
~FooBase()565   class FooBase { protected: ~FooBase() {} };
566   class Foo : public FooBase {
567   public:
568     operator int&() const;
569   };
570   void stuff();
571   template <typename T> class FooImpl : public Foo {
572     T val;
573   public:
FooImpl(const T & x)574     FooImpl(const T &x) : val(x) {}
~FooImpl()575     ~FooImpl() { stuff(); }
576   };
577 
makeFoo(const T & x)578   template <typename T> FooImpl<T> makeFoo(const T& x) {
579     return FooImpl<T>(x);
580   }
581 
test()582   void test() {
583     const Foo &x = makeFoo(42);
584     const int&y = makeFoo(42u);
585     (void)x;
586     (void)y;
587   };
588 }
589 
590 // PR 12325 - this was a false uninitialized value warning due to
591 // a broken CFG.
pr12325(int params)592 int pr12325(int params) {
593   int x = ({
594     while (false)
595       ;
596     int _v = params;
597     if (false)
598       ;
599     _v; // no-warning
600   });
601   return x;
602 }
603 
604 // Test lambda expressions with -Wuninitialized
test_lambda()605 int test_lambda() {
606   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}}
607   return f1(1, 2);
608 }
609 
610 namespace {
611   struct A {
612     enum { A1 };
A2__anon9f4f4b4f0211::A613     static int A2() {return 5;}
614     int A3;
A4__anon9f4f4b4f0211::A615     int A4() { return 5;}
616   };
617 
618   struct B {
619     A a;
620   };
621 
622   struct C {
C__anon9f4f4b4f0211::C623     C() {}
C__anon9f4f4b4f0211::C624     C(int x) {}
625     static A a;
626     B b;
627   };
628   A C::a = A();
629 
630   // Accessing non-static members will give a warning.
631   struct D {
632     C c;
D__anon9f4f4b4f0211::D633     D(char (*)[1]) : c(c.b.a.A1) {}
D__anon9f4f4b4f0211::D634     D(char (*)[2]) : c(c.b.a.A2()) {}
D__anon9f4f4b4f0211::D635     D(char (*)[3]) : c(c.b.a.A3) {}    // expected-warning {{field 'c' is uninitialized when used here}}
D__anon9f4f4b4f0211::D636     D(char (*)[4]) : c(c.b.a.A4()) {}  // expected-warning {{field 'c' is uninitialized when used here}}
637 
638     // c::a is static, so it is already initialized
D__anon9f4f4b4f0211::D639     D(char (*)[5]) : c(c.a.A1) {}
D__anon9f4f4b4f0211::D640     D(char (*)[6]) : c(c.a.A2()) {}
D__anon9f4f4b4f0211::D641     D(char (*)[7]) : c(c.a.A3) {}
D__anon9f4f4b4f0211::D642     D(char (*)[8]) : c(c.a.A4()) {}
643   };
644 
645   struct E {
646     int b = 1;
647     int c = 1;
648     int a;  // This field needs to be last to prevent the cross field
649             // uninitialized warning.
E__anon9f4f4b4f0211::E650     E(char (*)[1]) : a(a ? b : c) {}  // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E651     E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E652     E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E653     E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E654     E(char (*)[5]) : a(b ? c : b) {}
655 
E__anon9f4f4b4f0211::E656     E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E657     E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E658     E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E659     E(char (*)[9]) : a(b ?: c) {}
660 
E__anon9f4f4b4f0211::E661     E(char (*)[10]) : a((a, a, b)) {}
E__anon9f4f4b4f0211::E662     E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E663     E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E664     E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E665     E(char (*)[14]) : a((b, c, c)) {}
E__anon9f4f4b4f0211::E666     E(char (*)[15]) : a(b ?: a) {} // expected-warning {{field 'a' is uninitialized when used here}}
E__anon9f4f4b4f0211::E667     E(char (*)[16]) : a(a ?: b) {} // expected-warning {{field 'a' is uninitialized when used here}}
668   };
669 
670   struct F {
671     int a;
672     F* f;
F__anon9f4f4b4f0211::F673     F(int) {}
F__anon9f4f4b4f0211::F674     F() {}
675   };
676 
677   int F::*ptr = &F::a;
678   F* F::*f_ptr = &F::f;
679   struct G {
680     F f1, f2;
681     F *f3, *f4;
G__anon9f4f4b4f0211::G682     G(char (*)[1]) : f1(f1) {} // expected-warning {{field 'f1' is uninitialized when used here}}
G__anon9f4f4b4f0211::G683     G(char (*)[2]) : f2(f1) {}
G__anon9f4f4b4f0211::G684     G(char (*)[3]) : f2(F()) {}
685 
G__anon9f4f4b4f0211::G686     G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field 'f1' is uninitialized when used here}}
G__anon9f4f4b4f0211::G687     G(char (*)[5]) : f2(f1.*ptr) {}
688 
G__anon9f4f4b4f0211::G689     G(char (*)[6]) : f3(f3) {}  // expected-warning {{field 'f3' is uninitialized when used here}}
G__anon9f4f4b4f0211::G690     G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field 'f3' is uninitialized when used here}}
G__anon9f4f4b4f0211::G691     G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field 'f3' is uninitialized when used here}}
692   };
693 
694   struct H {
H__anon9f4f4b4f0211::H695     H() : a(a) {}  // expected-warning {{field 'a' is uninitialized when used here}}
696     const A a;
697   };
698 }
699 
700 namespace statics {
701   static int a = a; // no-warning: used to signal intended lack of initialization.
702   static int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
703   static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}}
704   static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
705   static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
706 
707   // Thes don't warn as they don't require the value.
708   static int g = sizeof(g);
709   int gg = g;  // Silence unneeded warning
710   static void* ptr = &ptr;
711   static int h = bar(&h);
712   static int i = boo(i);
713   static int j = far(j);
714   static int k = __alignof__(k);
715 
716   static int l = k ? l : l;  // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}}
717   static int m = 1 + (k ? m : m);  // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}}
718   static int n = -n;  // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
719   static int o = std::move(o); // expected-warning {{variable 'o' is uninitialized when used within its own initialization}}
720   static const int p = std::move(p); // expected-warning {{variable 'p' is uninitialized when used within its own initialization}}
721   static int q = moved(std::move(q)); // expected-warning {{variable 'q' is uninitialized when used within its own initialization}}
722   static int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
723   static int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
724   static int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
725   static int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
726   static int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
727   static int w = (w += 10); // expected-warning {{variable 'w' is uninitialized when used within its own initialization}}
728   static int x = x++; // expected-warning {{variable 'x' is uninitialized when used within its own initialization}}
729   static int y = ((s ? (y, v) : (77, y))++, sizeof(y)); // expected-warning {{variable 'y' is uninitialized when used within its own initialization}}
730   static int z = ++ref(z); // expected-warning {{variable 'z' is uninitialized when used within its own initialization}}
731   static int aa = (ref(aa) += 10); // expected-warning {{variable 'aa' is uninitialized when used within its own initialization}}
732   static int bb = bb ? x : y; // expected-warning {{variable 'bb' is uninitialized when used within its own initialization}}
733 
734 
test()735   void test() {
736     static int a = a; // no-warning: used to signal intended lack of initialization.
737     static int b = b + 1; // expected-warning {{static variable 'b' is suspiciously used within its own initialization}}
738     static int c = (c + c); // expected-warning 2{{static variable 'c' is suspiciously used within its own initialization}}
739     static int d = ({ d + d ;}); // expected-warning 2{{static variable 'd' is suspiciously used within its own initialization}}
740     static int e = static_cast<long>(e) + 1; // expected-warning {{static variable 'e' is suspiciously used within its own initialization}}
741     static int f = foo(f); // expected-warning {{static variable 'f' is suspiciously used within its own initialization}}
742 
743     // Thes don't warn as they don't require the value.
744     static int g = sizeof(g);
745     static void* ptr = &ptr;
746     static int h = bar(&h);
747     static int i = boo(i);
748     static int j = far(j);
749     static int k = __alignof__(k);
750 
751     static int l = k ? l : l;  // expected-warning 2{{static variable 'l' is suspiciously used within its own initialization}}
752     static int m = 1 + (k ? m : m);  // expected-warning 2{{static variable 'm' is suspiciously used within its own initialization}}
753     static int n = -n;  // expected-warning {{static variable 'n' is suspiciously used within its own initialization}}
754     static int o = std::move(o);  // expected-warning {{static variable 'o' is suspiciously used within its own initialization}}
755     static const int p = std::move(p);  // expected-warning {{static variable 'p' is suspiciously used within its own initialization}}
756     static int q = moved(std::move(q));  // expected-warning {{static variable 'q' is suspiciously used within its own initialization}}
757     static int r = std::move((p ? q : (18, r)));  // expected-warning {{static variable 'r' is suspiciously used within its own initialization}}
758     static int s = r ?: s;  // expected-warning {{static variable 's' is suspiciously used within its own initialization}}
759     static int t = t ?: s;  // expected-warning {{static variable 't' is suspiciously used within its own initialization}}
760     static int u = (foo(u), s);  // expected-warning {{static variable 'u' is suspiciously used within its own initialization}}
761     static int v = (u += v);  // expected-warning {{static variable 'v' is suspiciously used within its own initialization}}
762     static int w = (w += 10);  // expected-warning {{static variable 'w' is suspiciously used within its own initialization}}
763     static int x = x++;  // expected-warning {{static variable 'x' is suspiciously used within its own initialization}}
764     static int y = ((s ? (y, v) : (77, y))++, sizeof(y));  // expected-warning {{static variable 'y' is suspiciously used within its own initialization}}
765     static int z = ++ref(z); // expected-warning {{static variable 'z' is suspiciously used within its own initialization}}
766     static int aa = (ref(aa) += 10); // expected-warning {{static variable 'aa' is suspiciously used within its own initialization}}
767     static int bb = bb ? x : y; // expected-warning {{static variable 'bb' is suspiciously used within its own initialization}}
768 
769     for (;;) {
770       static int a = a; // no-warning: used to signal intended lack of initialization.
771       static int b = b + 1; // expected-warning {{static variable 'b' is suspiciously used within its own initialization}}
772       static int c = (c + c); // expected-warning 2{{static variable 'c' is suspiciously used within its own initialization}}
773       static int d = ({ d + d ;}); // expected-warning 2{{static variable 'd' is suspiciously used within its own initialization}}
774       static int e = static_cast<long>(e) + 1; // expected-warning {{static variable 'e' is suspiciously used within its own initialization}}
775       static int f = foo(f); // expected-warning {{static variable 'f' is suspiciously used within its own initialization}}
776 
777       // Thes don't warn as they don't require the value.
778       static int g = sizeof(g);
779       static void* ptr = &ptr;
780       static int h = bar(&h);
781       static int i = boo(i);
782       static int j = far(j);
783       static int k = __alignof__(k);
784 
785       static int l = k ? l : l;  // expected-warning 2{{static variable 'l' is suspiciously used within its own initialization}}
786       static int m = 1 + (k ? m : m); // expected-warning 2{{static variable 'm' is suspiciously used within its own initialization}}
787       static int n = -n;  // expected-warning {{static variable 'n' is suspiciously used within its own initialization}}
788       static int o = std::move(o);  // expected-warning {{static variable 'o' is suspiciously used within its own initialization}}
789       static const int p = std::move(p);  // expected-warning {{static variable 'p' is suspiciously used within its own initialization}}
790       static int q = moved(std::move(q));  // expected-warning {{static variable 'q' is suspiciously used within its own initialization}}
791       static int r = std::move((p ? q : (18, r)));  // expected-warning {{static variable 'r' is suspiciously used within its own initialization}}
792       static int s = r ?: s;  // expected-warning {{static variable 's' is suspiciously used within its own initialization}}
793       static int t = t ?: s;  // expected-warning {{static variable 't' is suspiciously used within its own initialization}}
794       static int u = (foo(u), s);  // expected-warning {{static variable 'u' is suspiciously used within its own initialization}}
795       static int v = (u += v);  // expected-warning {{static variable 'v' is suspiciously used within its own initialization}}
796       static int w = (w += 10);  // expected-warning {{static variable 'w' is suspiciously used within its own initialization}}
797       static int x = x++;  // expected-warning {{static variable 'x' is suspiciously used within its own initialization}}
798       static int y = ((s ? (y, v) : (77, y))++, sizeof(y));  // expected-warning {{static variable 'y' is suspiciously used within its own initialization}}
799       static int z = ++ref(z); // expected-warning {{static variable 'z' is suspiciously used within its own initialization}}
800       static int aa = (ref(aa) += 10); // expected-warning {{static variable 'aa' is suspiciously used within its own initialization}}
801       static int bb = bb ? x : y; // expected-warning {{static variable 'bb' is suspiciously used within its own initialization}}
802     }
803   }
804 }
805 
806 namespace in_class_initializers {
807   struct S {
Sin_class_initializers::S808     S() : a(a + 1) {} // expected-warning{{field 'a' is uninitialized when used here}}
809     int a = 42; // Note: because a is in a member initializer list, this initialization is ignored.
810   };
811 
812   struct T {
Tin_class_initializers::T813     T() : b(a + 1) {} // No-warning.
814     int a = 42;
815     int b;
816   };
817 
818   struct U {
Uin_class_initializers::U819     U() : a(b + 1), b(a + 1) {} // expected-warning{{field 'b' is uninitialized when used here}}
820     int a = 42; // Note: because a and b are in the member initializer list, these initializers are ignored.
821     int b = 1;
822   };
823 }
824 
825 namespace references {
826   int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}}
827   int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}}
828   int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}}
829   int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}}
830   int &e = d ?: e; // expected-warning{{reference 'e' is not yet bound to a value when used within its own initialization}}
831   int &f = f ?: d; // expected-warning{{reference 'f' is not yet bound to a value when used within its own initialization}}
832 
833   int &return_ref1(int);
834   int &return_ref2(int&);
835 
836   int &g = return_ref1(g); // expected-warning{{reference 'g' is not yet bound to a value when used within its own initialization}}
837   int &h = return_ref2(h); // expected-warning{{reference 'h' is not yet bound to a value when used within its own initialization}}
838 
839   struct S {
Sreferences::S840     S() : a(a) {} // expected-warning{{reference 'a' is not yet bound to a value when used here}}
841     int &a;
842   };
843 
test()844   void test() {
845     int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}}
846     int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}}
847     int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}}
848     int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}}
849   }
850 
851   struct T {
Treferences::T852     T() // expected-note{{during field initialization in this constructor}}
853      : a(b), b(a) {} // expected-warning{{reference 'b' is not yet bound to a value when used here}}
854     int &a, &b;
855     int &c = c; // expected-warning{{reference 'c' is not yet bound to a value when used here}}
856   };
857 
858   int x;
859   struct U {
Ureferences::U860     U() : b(a) {} // No-warning.
861     int &a = x;
862     int &b;
863   };
864 }
865 
866 namespace operators {
867   struct A {
868     A(bool);
869     bool operator==(A);
870   };
871 
872   A makeA();
873 
874   A a1 = a1 = makeA();  // expected-warning{{variable 'a1' is uninitialized when used within its own initialization}}
875   A a2 = a2 == a1;  // expected-warning{{variable 'a2' is uninitialized when used within its own initialization}}
876   A a3 = a2 == a3;  // expected-warning{{variable 'a3' is uninitialized when used within its own initialization}}
877 
878   int x = x = 5;
879 }
880 
881 namespace lambdas {
882   struct A {
Alambdas::A883     template<typename T> A(T) {}
884     int x;
885   };
__anon9f4f4b4f0402null886   A a0([] { return a0.x; }); // ok
f()887   void f() {
888     A a1([=] { return a1.x; }); // expected-warning{{variable 'a1' is uninitialized when used within its own initialization}}
889     A a2([&] { return a2.x; }); // ok
890   }
891 }
892 
893 namespace record_fields {
894   bool x;
895   struct A {
Arecord_fields::A896     A() {}
897     A get();
898     static A num();
899     static A copy(A);
900     static A something(A&);
901   };
902 
903   A ref(A&);
904   A const_ref(const A&);
905   A pointer(A*);
906   A normal(A);
907   A rref(A&&);
908 
909   struct B {
910     A a;
Brecord_fields::B911     B(char (*)[1]) : a(a) {}  // expected-warning {{uninitialized}}
Brecord_fields::B912     B(char (*)[2]) : a(a.get()) {}  // expected-warning {{uninitialized}}
Brecord_fields::B913     B(char (*)[3]) : a(a.num()) {}
Brecord_fields::B914     B(char (*)[4]) : a(a.copy(a)) {}  // expected-warning {{uninitialized}}
Brecord_fields::B915     B(char (*)[5]) : a(a.something(a)) {}
Brecord_fields::B916     B(char (*)[6]) : a(ref(a)) {}
Brecord_fields::B917     B(char (*)[7]) : a(const_ref(a)) {}
Brecord_fields::B918     B(char (*)[8]) : a(pointer(&a)) {}
Brecord_fields::B919     B(char (*)[9]) : a(normal(a)) {}  // expected-warning {{uninitialized}}
Brecord_fields::B920     B(char (*)[10]) : a(std::move(a)) {}  // expected-warning {{uninitialized}}
Brecord_fields::B921     B(char (*)[11]) : a(A(std::move(a))) {}  // expected-warning {{uninitialized}}
Brecord_fields::B922     B(char (*)[12]) : a(rref(std::move(a))) {}  // expected-warning {{uninitialized}}
Brecord_fields::B923     B(char (*)[13]) : a(std::move(x ? a : (25, a))) {}  // expected-warning 2{{uninitialized}}
924   };
925   struct C {
Crecord_fields::C926     C() {} // expected-note9{{in this constructor}}
927     A a1 = a1;  // expected-warning {{uninitialized}}
928     A a2 = a2.get();  // expected-warning {{uninitialized}}
929     A a3 = a3.num();
930     A a4 = a4.copy(a4);  // expected-warning {{uninitialized}}
931     A a5 = a5.something(a5);
932     A a6 = ref(a6);
933     A a7 = const_ref(a7);
934     A a8 = pointer(&a8);
935     A a9 = normal(a9);  // expected-warning {{uninitialized}}
936     const A a10 = a10;  // expected-warning {{uninitialized}}
937     A a11 = std::move(a11);  // expected-warning {{uninitialized}}
938     A a12 = A(std::move(a12));  // expected-warning {{uninitialized}}
939     A a13 = rref(std::move(a13));  // expected-warning {{uninitialized}}
940     A a14 = std::move(x ? a13 : (22, a14));  // expected-warning {{uninitialized}}
941   };
942   struct D {  // expected-note9{{in the implicit default constructor}}
943     A a1 = a1;  // expected-warning {{uninitialized}}
944     A a2 = a2.get();  // expected-warning {{uninitialized}}
945     A a3 = a3.num();
946     A a4 = a4.copy(a4);  // expected-warning {{uninitialized}}
947     A a5 = a5.something(a5);
948     A a6 = ref(a6);
949     A a7 = const_ref(a7);
950     A a8 = pointer(&a8);
951     A a9 = normal(a9);  // expected-warning {{uninitialized}}
952     const A a10 = a10;  // expected-warning {{uninitialized}}
953     A a11 = std::move(a11);  // expected-warning {{uninitialized}}
954     A a12 = A(std::move(a12));  // expected-warning {{uninitialized}}
955     A a13 = rref(std::move(a13));  // expected-warning {{uninitialized}}
956     A a14 = std::move(x ? a13 : (22, a14));  // expected-warning {{uninitialized}}
957   };
958   D d;
959   struct E {
960     A a1 = a1;
961     A a2 = a2.get();
962     A a3 = a3.num();
963     A a4 = a4.copy(a4);
964     A a5 = a5.something(a5);
965     A a6 = ref(a6);
966     A a7 = const_ref(a7);
967     A a8 = pointer(&a8);
968     A a9 = normal(a9);
969     const A a10 = a10;
970     A a11 = std::move(a11);
971     A a12 = A(std::move(a12));
972     A a13 = rref(std::move(a13));
973     A a14 = std::move(x ? a13 : (22, a14));
974   };
975 }
976 
977 namespace cross_field_warnings {
978   struct A {
979     int a, b;
Across_field_warnings::A980     A() {}
Across_field_warnings::A981     A(char (*)[1]) : b(a) {}  // expected-warning{{field 'a' is uninitialized when used here}}
Across_field_warnings::A982     A(char (*)[2]) : a(b) {}  // expected-warning{{field 'b' is uninitialized when used here}}
983   };
984 
985   struct B {
986     int a = b;  // expected-warning{{field 'b' is uninitialized when used here}}
987     int b;
Bcross_field_warnings::B988     B() {} // expected-note{{during field initialization in this constructor}}
989   };
990 
991   struct C {
992     int a;
993     int b = a;  // expected-warning{{field 'a' is uninitialized when used here}}
Ccross_field_warnings::C994     C(char (*)[1]) : a(5) {}
Ccross_field_warnings::C995     C(char (*)[2]) {} // expected-note{{during field initialization in this constructor}}
996   };
997 
998   struct D {
999     int a;
1000     int &b;
1001     int &c = a;
1002     int d = b;
Dcross_field_warnings::D1003     D() : b(a) {}
1004   };
1005 
1006   struct E {
1007     int a;
1008     int get();
1009     static int num();
Ecross_field_warnings::E1010     E() {}
Ecross_field_warnings::E1011     E(int) {}
1012   };
1013 
1014   struct F {
1015     int a;
1016     E e;
1017     int b;
Fcross_field_warnings::F1018     F(char (*)[1]) : a(e.get()) {}  // expected-warning{{field 'e' is uninitialized when used here}}
Fcross_field_warnings::F1019     F(char (*)[2]) : a(e.num()) {}
Fcross_field_warnings::F1020     F(char (*)[3]) : e(a) {}  // expected-warning{{field 'a' is uninitialized when used here}}
Fcross_field_warnings::F1021     F(char (*)[4]) : a(4), e(a) {}
Fcross_field_warnings::F1022     F(char (*)[5]) : e(b) {}  // expected-warning{{field 'b' is uninitialized when used here}}
Fcross_field_warnings::F1023     F(char (*)[6]) : e(b), b(4) {}  // expected-warning{{field 'b' is uninitialized when used here}}
1024   };
1025 
1026   struct G {
Gcross_field_warnings::G1027     G(const A&) {};
1028   };
1029 
1030   struct H {
1031     A a1;
1032     G g;
1033     A a2;
Hcross_field_warnings::H1034     H() : g(a1) {}
Hcross_field_warnings::H1035     H(int) : g(a2) {}
1036   };
1037 
1038   struct I {
Icross_field_warnings::I1039     I(int*) {}
1040   };
1041 
1042   struct J : public I {
1043     int *a;
1044     int *b;
1045     int c;
Jcross_field_warnings::J1046     J() : I((a = new int(5))), b(a), c(*a) {}
1047   };
1048 
1049   struct K {
1050     int a = (b = 5);
1051     int b = b + 5;
1052   };
1053 
1054   struct L {
1055     int a = (b = 5);
1056     int b = b + 5;  // expected-warning{{field 'b' is uninitialized when used here}}
Lcross_field_warnings::L1057     L() : a(5) {}  // expected-note{{during field initialization in this constructor}}
1058   };
1059 
1060   struct M { };
1061 
1062   struct N : public M {
1063     int a;
1064     int b;
Ncross_field_warnings::N1065     N() : b(a) { }  // expected-warning{{field 'a' is uninitialized when used here}}
1066   };
1067 
1068   struct O {
1069     int x = 42;
getcross_field_warnings::O1070     int get() { return x; }
1071   };
1072 
1073   struct P {
1074     O o;
1075     int x = o.get();
Pcross_field_warnings::P1076     P() : x(o.get()) { }
1077   };
1078 
1079   struct Q {
1080     int a;
1081     int b;
1082     int &c;
Qcross_field_warnings::Q1083     Q() :
1084       a(c = 5),  // expected-warning{{reference 'c' is not yet bound to a value when used here}}
1085       b(c),  // expected-warning{{reference 'c' is not yet bound to a value when used here}}
1086       c(a) {}
1087   };
1088 
1089   struct R {
1090     int a;
1091     int b;
1092     int c;
1093     int d = a + b + c;
Rcross_field_warnings::R1094     R() : a(c = 5), b(c), c(a) {}
1095   };
1096 
1097   // FIXME: Use the CFG-based analysis to give a sometimes uninitialized
1098   // warning on y.
1099   struct T {
1100     int x;
1101     int y;
Tcross_field_warnings::T1102     T(bool b)
1103         : x(b ? (y = 5) : (1 + y)),  // expected-warning{{field 'y' is uninitialized when used here}}
1104           y(y + 1) {}
Tcross_field_warnings::T1105     T(int b)
1106         : x(!b ? (1 + y) : (y = 5)),  // expected-warning{{field 'y' is uninitialized when used here}}
1107           y(y + 1) {}
1108   };
1109 
1110 }
1111 
1112 namespace base_class {
1113   struct A {
Abase_class::A1114     A (int) {}
1115   };
1116 
1117   struct B : public A {
1118     int x;
Bbase_class::B1119     B() : A(x) {}   // expected-warning{{field 'x' is uninitialized when used here}}
1120   };
1121 
1122   struct C : public A {
1123     int x;
1124     int y;
Cbase_class::C1125     C() : A(y = 4), x(y) {}
1126   };
1127 }
1128 
1129 namespace delegating_constructor {
1130   struct A {
1131     A(int);
1132     A(int&, int);
1133 
Adelegating_constructor::A1134     A(char (*)[1]) : A(x) {}
1135     // expected-warning@-1 {{field 'x' is uninitialized when used here}}
Adelegating_constructor::A1136     A(char (*)[2]) : A(x, x) {}
1137     // expected-warning@-1 {{field 'x' is uninitialized when used here}}
1138 
Adelegating_constructor::A1139     A(char (*)[3]) : A(x, 0) {}
1140 
1141     int x;
1142   };
1143 }
1144 
1145 namespace init_list {
1146   int num = 5;
1147   struct A { int i1, i2; };
1148   struct B { A a1, a2; };
1149 
1150   A a1{1,2};
1151   A a2{a2.i1 + 2};  // expected-warning{{uninitialized}}
1152   A a3 = {a3.i1 + 2};  // expected-warning{{uninitialized}}
1153   A a4 = A{a4.i2 + 2};  // expected-warning{{uninitialized}}
1154 
1155   B b1 = { {}, {} };
1156   B b2 = { {}, b2.a1 };
1157   B b3 = { b3.a1 };  // expected-warning{{uninitialized}}
1158   B b4 = { {}, b4.a2} ;  // expected-warning{{uninitialized}}
1159   B b5 = { b5.a2 };  // expected-warning{{uninitialized}}
1160 
1161   B b6 = { {b6.a1.i1} };  // expected-warning{{uninitialized}}
1162   B b7 = { {0, b7.a1.i1} };
1163   B b8 = { {}, {b8.a1.i1} };
1164   B b9 = { {}, {0, b9.a1.i1} };
1165 
1166   B b10 = { {b10.a1.i2} };  // expected-warning{{uninitialized}}
1167   B b11 = { {0, b11.a1.i2} };  // expected-warning{{uninitialized}}
1168   B b12 = { {}, {b12.a1.i2} };
1169   B b13 = { {}, {0, b13.a1.i2} };
1170 
1171   B b14 = { {b14.a2.i1} };  // expected-warning{{uninitialized}}
1172   B b15 = { {0, b15.a2.i1} };  // expected-warning{{uninitialized}}
1173   B b16 = { {}, {b16.a2.i1} };  // expected-warning{{uninitialized}}
1174   B b17 = { {}, {0, b17.a2.i1} };
1175 
1176   B b18 = { {b18.a2.i2} };  // expected-warning{{uninitialized}}
1177   B b19 = { {0, b19.a2.i2} };  // expected-warning{{uninitialized}}
1178   B b20 = { {}, {b20.a2.i2} };  // expected-warning{{uninitialized}}
1179   B b21 = { {}, {0, b21.a2.i2} };  // expected-warning{{uninitialized}}
1180 
1181   B b22 = { {b18.a2.i2 + 5} };
1182 
1183   struct C {int a; int& b; int c; };
1184   C c1 = { 0, num, 0 };
1185   C c2 = { 1, num, c2.b };
1186   C c3 = { c3.b, num };  // expected-warning{{uninitialized}}
1187   C c4 = { 0, c4.b, 0 };  // expected-warning{{uninitialized}}
1188   C c5 = { 0, c5.c, 0 };
1189   C c6 = { c6.b, num, 0 };  // expected-warning{{uninitialized}}
1190   C c7 = { 0, c7.a, 0 };
1191 
1192   struct D {int &a; int &b; };
1193   D d1 = { num, num };
1194   D d2 = { num, d2.a };
1195   D d3 = { d3.b, num };  // expected-warning{{uninitialized}}
1196 
1197   // Same as above in member initializer form.
1198   struct Awrapper {
1199     A a1{1,2};
1200     A a2{a2.i1 + 2};  // expected-warning{{uninitialized}}
1201     A a3 = {a3.i1 + 2};  // expected-warning{{uninitialized}}
1202     A a4 = A{a4.i2 + 2};  // expected-warning{{uninitialized}}
Awrapperinit_list::Awrapper1203     Awrapper() {}  // expected-note 3{{in this constructor}}
Awrapperinit_list::Awrapper1204     Awrapper(int) :
1205       a1{1,2},
1206       a2{a2.i1 + 2},  // expected-warning{{uninitialized}}
1207       a3{a3.i1 + 2},  // expected-warning{{uninitialized}}
1208       a4{a4.i2 + 2}  // expected-warning{{uninitialized}}
1209     {}
1210   };
1211 
1212   struct Bwrapper {
1213     B b1 = { {}, {} };
1214     B b2 = { {}, b2.a1 };
1215     B b3 = { b3.a1 };  // expected-warning{{uninitialized}}
1216     B b4 = { {}, b4.a2} ;  // expected-warning{{uninitialized}}
1217     B b5 = { b5.a2 };  // expected-warning{{uninitialized}}
1218 
1219     B b6 = { {b6.a1.i1} };  // expected-warning{{uninitialized}}
1220     B b7 = { {0, b7.a1.i1} };
1221     B b8 = { {}, {b8.a1.i1} };
1222     B b9 = { {}, {0, b9.a1.i1} };
1223 
1224     B b10 = { {b10.a1.i2} };  // expected-warning{{uninitialized}}
1225     B b11 = { {0, b11.a1.i2} };  // expected-warning{{uninitialized}}
1226     B b12 = { {}, {b12.a1.i2} };
1227     B b13 = { {}, {0, b13.a1.i2} };
1228 
1229     B b14 = { {b14.a2.i1} };  // expected-warning{{uninitialized}}
1230     B b15 = { {0, b15.a2.i1} };  // expected-warning{{uninitialized}}
1231     B b16 = { {}, {b16.a2.i1} };  // expected-warning{{uninitialized}}
1232     B b17 = { {}, {0, b17.a2.i1} };
1233 
1234     B b18 = { {b18.a2.i2} };  // expected-warning{{uninitialized}}
1235     B b19 = { {0, b19.a2.i2} };  // expected-warning{{uninitialized}}
1236     B b20 = { {}, {b20.a2.i2} };  // expected-warning{{uninitialized}}
1237     B b21 = { {}, {0, b21.a2.i2} };  // expected-warning{{uninitialized}}
1238 
1239     B b22 = { {b18.a2.i2 + 5} };
Bwrapperinit_list::Bwrapper1240     Bwrapper() {}  // expected-note 13{{in this constructor}}
Bwrapperinit_list::Bwrapper1241     Bwrapper(int) :
1242       b1{ {}, {} },
1243       b2{ {}, b2.a1 },
1244       b3{ b3.a1 },  // expected-warning{{uninitialized}}
1245       b4{ {}, b4.a2}, // expected-warning{{uninitialized}}
1246       b5{ b5.a2 },  // expected-warning{{uninitialized}}
1247 
1248       b6{ {b6.a1.i1} },  // expected-warning{{uninitialized}}
1249       b7{ {0, b7.a1.i1} },
1250       b8{ {}, {b8.a1.i1} },
1251       b9{ {}, {0, b9.a1.i1} },
1252 
1253       b10{ {b10.a1.i2} },  // expected-warning{{uninitialized}}
1254       b11{ {0, b11.a1.i2} },  // expected-warning{{uninitialized}}
1255       b12{ {}, {b12.a1.i2} },
1256       b13{ {}, {0, b13.a1.i2} },
1257 
1258       b14{ {b14.a2.i1} },  // expected-warning{{uninitialized}}
1259       b15{ {0, b15.a2.i1} },  // expected-warning{{uninitialized}}
1260       b16{ {}, {b16.a2.i1} },  // expected-warning{{uninitialized}}
1261       b17{ {}, {0, b17.a2.i1} },
1262 
1263       b18{ {b18.a2.i2} },  // expected-warning{{uninitialized}}
1264       b19{ {0, b19.a2.i2} },  // expected-warning{{uninitialized}}
1265       b20{ {}, {b20.a2.i2} },  // expected-warning{{uninitialized}}
1266       b21{ {}, {0, b21.a2.i2} },  // expected-warning{{uninitialized}}
1267 
1268       b22{ {b18.a2.i2 + 5} }
1269     {}
1270   };
1271 
1272   struct Cwrapper {
1273     C c1 = { 0, num, 0 };
1274     C c2 = { 1, num, c2.b };
1275     C c3 = { c3.b, num };  // expected-warning{{uninitialized}}
1276     C c4 = { 0, c4.b, 0 };  // expected-warning{{uninitialized}}
1277     C c5 = { 0, c5.c, 0 };
1278     C c6 = { c6.b, num, 0 };  // expected-warning{{uninitialized}}
1279     C c7 = { 0, c7.a, 0 };
1280 
Cwrapperinit_list::Cwrapper1281     Cwrapper() {} // expected-note 3{{in this constructor}}
Cwrapperinit_list::Cwrapper1282     Cwrapper(int) :
1283       c1{ 0, num, 0 },
1284       c2{ 1, num, c2.b },
1285       c3{ c3.b, num },  // expected-warning{{uninitialized}}
1286       c4{ 0, c4.b, 0 },  // expected-warning{{uninitialized}}
1287       c5{ 0, c5.c, 0 },
1288       c6{ c6.b, num, 0 },  // expected-warning{{uninitialized}}
1289       c7{ 0, c7.a, 0 }
1290     {}
1291   };
1292 
1293   struct Dwrapper {
1294     D d1 = { num, num };
1295     D d2 = { num, d2.a };
1296     D d3 = { d3.b, num }; // expected-warning{{uninitialized}}
Dwrapperinit_list::Dwrapper1297     Dwrapper() {}  // expected-note{{in this constructor}}
Dwrapperinit_list::Dwrapper1298     Dwrapper(int) :
1299       d1{ num, num },
1300       d2{ num, d2.a },
1301       d3{ d3.b, num } // expected-warning{{uninitialized}}
1302     {}
1303   };
1304 }
1305 
1306 namespace template_class {
1307 class Foo {
1308  public:
Create()1309     int *Create() { return nullptr; }
1310 };
1311 
1312 template <typename T>
1313 class A {
1314 public:
1315   // Don't warn on foo here.
A()1316   A() : ptr(foo->Create()) {}
1317 
1318 private:
1319   Foo *foo = new Foo;
1320   int *ptr;
1321 };
1322 
1323 template <typename T>
1324 class B {
1325 public:
1326   // foo is uninitialized here, but class B is never instantiated.
B()1327   B() : ptr(foo->Create()) {}
1328 
1329 private:
1330   Foo *foo;
1331   int *ptr;
1332 };
1333 
1334 template <typename T>
1335 class C {
1336 public:
C()1337   C() : ptr(foo->Create()) {}
1338   // expected-warning@-1 {{field 'foo' is uninitialized when used here}}
1339 private:
1340   Foo *foo;
1341   int *ptr;
1342 };
1343 
1344 C<int> c;
1345 // expected-note@-1 {{in instantiation of member function 'template_class::C<int>::C' requested here}}
1346 
1347 }
1348 
1349 namespace base_class_access {
1350 struct A {
1351   A();
1352   A(int);
1353 
1354   int i;
1355   int foo();
1356 
1357   static int bar();
1358 };
1359 
1360 struct B : public A {
Bbase_class_access::B1361   B(int (*)[1]) : A() {}
Bbase_class_access::B1362   B(int (*)[2]) : A(bar()) {}
1363 
Bbase_class_access::B1364   B(int (*)[3]) : A(i) {}
1365   // expected-warning@-1 {{base class 'base_class_access::A' is uninitialized when used here to access 'base_class_access::A::i'}}
1366 
Bbase_class_access::B1367   B(int (*)[4]) : A(foo()) {}
1368   // expected-warning@-1 {{base_class_access::A' is uninitialized when used here to access 'base_class_access::A::foo'}}
1369 };
1370 
1371 struct C {
Cbase_class_access::C1372   C(int) {}
1373 };
1374 
1375 struct D : public C, public A {
Dbase_class_access::D1376   D(int (*)[1]) : C(0) {}
Dbase_class_access::D1377   D(int (*)[2]) : C(bar()) {}
1378 
Dbase_class_access::D1379   D(int (*)[3]) : C(i) {}
1380   // expected-warning@-1 {{base class 'base_class_access::A' is uninitialized when used here to access 'base_class_access::A::i'}}
1381 
Dbase_class_access::D1382   D(int (*)[4]) : C(foo()) {}
1383   // expected-warning@-1 {{base_class_access::A' is uninitialized when used here to access 'base_class_access::A::foo'}}
1384 };
1385 
1386 }
1387 
1388 namespace value {
1389 template <class T> T move(T t);
1390 template <class T> T notmove(T t);
1391 }
1392 namespace lvalueref {
1393 template <class T> T move(T& t);
1394 template <class T> T notmove(T& t);
1395 }
1396 namespace rvalueref {
1397 template <class T> T move(T&& t);
1398 template <class T> T notmove(T&& t);
1399 }
1400 
1401 namespace move_test {
1402 int a1 = std::move(a1); // expected-warning {{uninitialized}}
1403 int a2 = value::move(a2); // expected-warning {{uninitialized}}
1404 int a3 = value::notmove(a3); // expected-warning {{uninitialized}}
1405 int a4 = lvalueref::move(a4);
1406 int a5 = lvalueref::notmove(a5);
1407 int a6 = rvalueref::move(a6);
1408 int a7 = rvalueref::notmove(a7);
1409 
test()1410 void test() {
1411   int a1 = std::move(a1); // expected-warning {{uninitialized}}
1412   int a2 = value::move(a2); // expected-warning {{uninitialized}}
1413   int a3 = value::notmove(a3); // expected-warning {{uninitialized}}
1414   int a4 = lvalueref::move(a4);
1415   int a5 = lvalueref::notmove(a5);
1416   int a6 = rvalueref::move(a6);
1417   int a7 = rvalueref::notmove(a7);
1418 }
1419 
1420 class A {
1421   int a;
A(int (*)[1])1422   A(int (*) [1]) : a(std::move(a)) {} // expected-warning {{uninitialized}}
A(int (*)[2])1423   A(int (*) [2]) : a(value::move(a)) {} // expected-warning {{uninitialized}}
A(int (*)[3])1424   A(int (*) [3]) : a(value::notmove(a)) {} // expected-warning {{uninitialized}}
A(int (*)[4])1425   A(int (*) [4]) : a(lvalueref::move(a)) {}
A(int (*)[5])1426   A(int (*) [5]) : a(lvalueref::notmove(a)) {}
A(int (*)[6])1427   A(int (*) [6]) : a(rvalueref::move(a)) {}
A(int (*)[7])1428   A(int (*) [7]) : a(rvalueref::notmove(a)) {}
1429 };
1430 }
1431 
array_capture(bool b)1432 void array_capture(bool b) {
1433   const char fname[] = "array_capture";
1434   if (b) {
1435     int unused; // expected-warning {{unused variable}}
1436   } else {
1437     [fname]{};
1438   }
1439 }
1440