blob: c46b30640fb2b9e4972749e5705f4cc82b4dce7a [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregorcaaf29a2008-12-10 23:01:14 +00002// rdar://6425550
3int bar();
4void do_something(int);
Douglas Gregor9c4b8382009-11-05 17:49:26 +00005int *get_ptr();
Douglas Gregorcaaf29a2008-12-10 23:01:14 +00006
7int foo() {
8 if (int X = bar()) {
9 return X;
10 } else {
11 do_something(X); // expected-warning{{'X' is always zero in this context}}
Mike Stumpd1969d82009-07-22 00:43:08 +000012 return 0;
Douglas Gregorcaaf29a2008-12-10 23:01:14 +000013 }
14}
15
16bool 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}}
Douglas Gregor9c4b8382009-11-05 17:49:26 +000029 do_something(B2); // expected-warning{{'B2' is always false in this context}}
Douglas Gregorcaaf29a2008-12-10 23:01:14 +000030 }
31 return B; // expected-warning{{'B' is always false in this context}}
32 }
33}
Douglas Gregor9c4b8382009-11-05 17:49:26 +000034
35void 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}