Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | caaf29a | 2008-12-10 23:01:14 +0000 | [diff] [blame] | 2 | // rdar://6425550 |
| 3 | int bar(); |
| 4 | void do_something(int); |
| 5 | |
| 6 | int foo() { |
| 7 | if (int X = bar()) { |
| 8 | return X; |
| 9 | } else { |
| 10 | do_something(X); // expected-warning{{'X' is always zero in this context}} |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 11 | return 0; |
Douglas Gregor | caaf29a | 2008-12-10 23:01:14 +0000 | [diff] [blame] | 12 | } |
| 13 | } |
| 14 | |
| 15 | bool foo2() { |
| 16 | if (bool B = bar()) { |
| 17 | if (int Y = bar()) { |
| 18 | return B; |
| 19 | } else { |
| 20 | do_something(Y); // expected-warning{{'Y' is always zero in this context}} |
| 21 | return B; |
| 22 | } |
| 23 | } else { |
| 24 | if (bool B2 = B) { // expected-warning{{'B' is always false in this context}} |
| 25 | do_something(B); // expected-warning{{'B' is always false in this context}} |
| 26 | } else if (B2) { // expected-warning{{'B2' is always false in this context}} |
| 27 | do_something(B); // expected-warning{{'B' is always false in this context}} |
| 28 | } |
| 29 | return B; // expected-warning{{'B' is always false in this context}} |
| 30 | } |
| 31 | } |