uninit-variables.cpp revision 1b528445016c2dba23babeea07e352ca8b816262
1// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only %s -verify
2
3int test1_aux(int &x);
4int test1() {
5  int x;
6  test1_aux(x);
7  return x; // no-warning
8}
9
10int test2_aux() {
11  int x;
12  int &y = x;
13  return x; // no-warning
14}
15
16// Handle cases where the CFG may constant fold some branches, thus
17// mitigating the need for some path-sensitivity in the analysis.
18unsigned test3_aux();
19unsigned test3() {
20  unsigned x = 0;
21  const bool flag = true;
22  if (flag && (x = test3_aux()) == 0) {
23    return x;
24  }
25  return x;
26}
27unsigned test3_b() {
28  unsigned x ;
29  const bool flag = true;
30  if (flag && (x = test3_aux()) == 0) {
31    x = 1;
32  }
33  return x; // no-warning
34}
35unsigned test3_c() {
36  unsigned x; // expected-note{{declared here}} expected-note{{add initialization}}
37  const bool flag = false;
38  if (flag && (x = test3_aux()) == 0) {
39    x = 1;
40  }
41  return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
42}
43
44enum test4_A {
45 test4_A_a, test_4_A_b
46};
47test4_A test4() {
48 test4_A a; // expected-note{{variable 'a' is declared here}}
49 return a; // expected-warning{{variable 'a' is possibly uninitialized when used here}}
50}
51
52