Ted Kremenek | 1a8641c | 2014-03-15 01:26:32 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s |
Mike Stump | 1bacb81 | 2010-01-13 02:59:54 +0000 | [diff] [blame] | 2 | |
| 3 | int j; |
Ted Kremenek | 7549f0f | 2014-03-06 01:09:45 +0000 | [diff] [blame] | 4 | int bar(); |
Mike Stump | 1bacb81 | 2010-01-13 02:59:54 +0000 | [diff] [blame] | 5 | int test1() { |
| 6 | for (int i = 0; |
| 7 | i != 10; |
Ted Kremenek | 1421037 | 2014-03-21 06:02:36 +0000 | [diff] [blame] | 8 | ++i) { // expected-warning {{loop will run at most once (loop increment never executed)}} |
Mike Stump | 1bacb81 | 2010-01-13 02:59:54 +0000 | [diff] [blame] | 9 | if (j == 23) // missing {}'s |
| 10 | bar(); |
| 11 | return 1; |
| 12 | } |
| 13 | return 0; |
Ted Kremenek | 7549f0f | 2014-03-06 01:09:45 +0000 | [diff] [blame] | 14 | return 1; // expected-warning {{will never be executed}} |
| 15 | } |
| 16 | |
| 17 | int test1_B() { |
| 18 | for (int i = 0; |
| 19 | i != 10; |
Ted Kremenek | 1421037 | 2014-03-21 06:02:36 +0000 | [diff] [blame] | 20 | ++i) { // expected-warning {{loop will run at most once (loop increment never executed)}} |
Ted Kremenek | 7549f0f | 2014-03-06 01:09:45 +0000 | [diff] [blame] | 21 | if (j == 23) // missing {}'s |
| 22 | bar(); |
| 23 | return 1; |
| 24 | } |
| 25 | return 0; |
| 26 | return bar(); // expected-warning {{will never be executed}} |
Mike Stump | 1bacb81 | 2010-01-13 02:59:54 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void test2(int i) { |
| 30 | switch (i) { |
| 31 | case 0: |
| 32 | break; |
| 33 | bar(); // expected-warning {{will never be executed}} |
| 34 | case 2: |
| 35 | switch (i) { |
| 36 | default: |
| 37 | a: goto a; |
| 38 | } |
| 39 | bar(); // expected-warning {{will never be executed}} |
| 40 | } |
| 41 | b: goto b; |
| 42 | bar(); // expected-warning {{will never be executed}} |
| 43 | } |
| 44 | |
| 45 | void test3() { |
| 46 | ^{ return; |
| 47 | bar(); // expected-warning {{will never be executed}} |
| 48 | }(); |
| 49 | while (++j) { |
| 50 | continue; |
| 51 | bar(); // expected-warning {{will never be executed}} |
| 52 | } |
| 53 | } |
Ted Kremenek | 82bfc86 | 2010-08-28 00:19:02 +0000 | [diff] [blame] | 54 | |
| 55 | // PR 6130 - Don't warn about bogus unreachable code with throw's and |
| 56 | // temporary objects. |
| 57 | class PR6130 { |
| 58 | public: |
| 59 | PR6130(); |
| 60 | ~PR6130(); |
| 61 | }; |
| 62 | |
| 63 | int pr6130(unsigned i) { |
| 64 | switch(i) { |
| 65 | case 0: return 1; |
| 66 | case 1: return 2; |
| 67 | default: |
| 68 | throw PR6130(); // no-warning |
| 69 | } |
| 70 | } |