]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/warn-for-var-in-else.cpp
Update clang to r100181.
[FreeBSD/FreeBSD.git] / test / SemaCXX / warn-for-var-in-else.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // rdar://6425550
3 int bar();
4 void do_something(int);
5 int *get_ptr();
6
7 int foo() {
8   if (int X = bar()) {
9     return X;
10   } else {
11     do_something(X); // expected-warning{{'X' is always zero in this context}}
12     return 0;
13   }
14 }
15
16 bool foo2() {
17   if (bool B = bar()) {
18     if (int Y = bar()) {
19       return B;
20     } else {
21       do_something(Y); // expected-warning{{'Y' is always zero in this context}}
22       return B;
23     }
24   } else {
25     if (bool B2 = B) { // expected-warning{{'B' is always false in this context}}
26       do_something(B); // expected-warning{{'B' is always false in this context}}
27     } else if (B2) {  // expected-warning{{'B2' is always false in this context}}
28       do_something(B); // expected-warning{{'B' is always false in this context}}
29       do_something(B2); // expected-warning{{'B2' is always false in this context}}
30     }
31     return B; // expected-warning{{'B' is always false in this context}}
32   }
33 }
34
35 void foo3() {  
36   if (int *P1 = get_ptr())
37     do_something(*P1);
38   else if (int *P2 = get_ptr()) {
39     do_something(*P1); // expected-warning{{'P1' is always NULL in this context}}
40     do_something(*P2);
41   } else {
42     do_something(*P1); // expected-warning{{'P1' is always NULL in this context}}
43     do_something(*P2); // expected-warning{{'P2' is always NULL in this context}}
44   }
45 }