blob: 3c8a429b3e585116097f4f091549c971b260622f [file] [log] [blame]
Anders Carlsson479d6f52011-02-19 19:23:03 +00001// RUN: %clang_cc1 %s -fexceptions -fsyntax-only -verify -fblocks -Wunreachable-code -Wno-unused-value
Mike Stump04c68512010-01-21 15:20:48 +00002
Anders Carlssonaf7534f2010-09-03 00:25:02 +00003int &halt() __attribute__((noreturn));
Mike Stumpcc3a8532010-01-21 17:21:23 +00004int &live();
Mike Stump04c68512010-01-21 15:20:48 +00005int dead();
6int liveti() throw(int);
7int (*livetip)() throw(int);
8
9int test1() {
10 try {
11 live();
12 } catch (int i) {
13 live();
14 }
15 return 1;
16}
17
18void test2() {
19 try {
20 live();
21 } catch (int i) {
22 live();
23 }
24 try {
25 liveti();
26 } catch (int i) {
27 live();
28 }
29 try {
30 livetip();
31 } catch (int i) {
32 live();
33 }
34 throw 1;
35 dead(); // expected-warning {{will never be executed}}
36}
Mike Stumpcc3a8532010-01-21 17:21:23 +000037
38
39void test3() {
40 halt()
41 --; // expected-warning {{will never be executed}}
Ted Kremenekf8e4b482010-12-16 08:22:16 +000042 // FIXME: The unreachable part is just the '?', but really all of this
43 // code is unreachable and shouldn't be separately reported.
44 halt() // expected-warning {{will never be executed}}
45 ?
Mike Stumpc18c4032010-01-21 19:44:04 +000046 dead() : dead();
Mike Stumpfcd6f942010-01-21 22:12:18 +000047 live(),
48 float // expected-warning {{will never be executed}}
49 (halt());
Mike Stumpcc3a8532010-01-21 17:21:23 +000050}
Mike Stump60dbeeb2010-01-21 23:15:53 +000051
52void test4() {
53 struct S {
54 int mem;
55 } s;
56 S &foor();
Zhongxing Xua396e612010-02-24 02:19:28 +000057 halt(), foor()// expected-warning {{will never be executed}}
58 .mem;
Mike Stump60dbeeb2010-01-21 23:15:53 +000059}
60
61void test5() {
62 struct S {
63 int mem;
64 } s;
Anders Carlssonaf7534f2010-09-03 00:25:02 +000065 S &foor() __attribute__((noreturn));
Mike Stump60dbeeb2010-01-21 23:15:53 +000066 foor()
67 .mem; // expected-warning {{will never be executed}}
68}
69
70void test6() {
71 struct S {
72 ~S() { }
73 S(int i) { }
74 };
75 live(),
76 S // expected-warning {{will never be executed}}
77 (halt());
78}