warn-unreachable.cpp revision 5d1d7ae120c2c8e6cba5d2a712b33500a5aecc10
1// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wunreachable-code -Wno-unused-value
2
3int &halt() __attribute__((noreturn));
4int &live();
5int 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}
37
38
39void test3() {
40  halt()
41    --;         // expected-warning {{will never be executed}}
42  halt()
43    ?           // expected-warning {{will never be executed}}
44    dead() : dead();
45  live(),
46    float       // expected-warning {{will never be executed}}
47      (halt());
48}
49
50void test4() {
51  struct S {
52    int mem;
53  } s;
54  S &foor();
55  halt(), foor()// expected-warning {{will never be executed}}
56    .mem;
57}
58
59void test5() {
60  struct S {
61    int mem;
62  } s;
63  S &foor() __attribute__((noreturn));
64  foor()
65    .mem;       // expected-warning {{will never be executed}}
66}
67
68void test6() {
69  struct S {
70    ~S() { }
71    S(int i) { }
72  };
73  live(),
74    S            // expected-warning {{will never be executed}}
75      (halt());
76}
77