blob: 743290e1b9e55884e27b5e38c8fb196f123184bb [file] [log] [blame]
Anders Carlssonabea9512011-02-28 00:40:07 +00001// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code -fblocks -verify %s
Mike Stumpfa6ef182010-01-13 02:59:54 +00002
3int j;
4void bar() { }
5int test1() {
6 for (int i = 0;
7 i != 10;
8 ++i) { // expected-warning {{will never be executed}}
9 if (j == 23) // missing {}'s
10 bar();
11 return 1;
12 }
13 return 0;
14 return 1; // expected-warning {{will never be executed}}
15}
16
17void test2(int i) {
18 switch (i) {
19 case 0:
20 break;
21 bar(); // expected-warning {{will never be executed}}
22 case 2:
23 switch (i) {
24 default:
25 a: goto a;
26 }
27 bar(); // expected-warning {{will never be executed}}
28 }
29 b: goto b;
30 bar(); // expected-warning {{will never be executed}}
31}
32
33void test3() {
34 ^{ return;
35 bar(); // expected-warning {{will never be executed}}
36 }();
37 while (++j) {
38 continue;
39 bar(); // expected-warning {{will never be executed}}
40 }
41}
Ted Kremenek47e331e2010-08-28 00:19:02 +000042
43// PR 6130 - Don't warn about bogus unreachable code with throw's and
44// temporary objects.
45class PR6130 {
46public:
47 PR6130();
48 ~PR6130();
49};
50
51int pr6130(unsigned i) {
52 switch(i) {
53 case 0: return 1;
54 case 1: return 2;
55 default:
56 throw PR6130(); // no-warning
57 }
58}