Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 %s -fcxx-exceptions -fexceptions -fsyntax-only -verify -fblocks -Wunreachable-code -Wno-unused-value
      2 
      3 int &halt() __attribute__((noreturn));
      4 int &live();
      5 int dead();
      6 int liveti() throw(int);
      7 int (*livetip)() throw(int);
      8 
      9 int test1() {
     10   try {
     11     live();
     12   } catch (int i) {
     13     live();
     14   }
     15   return 1;
     16 }
     17 
     18 void 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 
     39 void test3() {
     40   halt()
     41     --;         // expected-warning {{will never be executed}}
     42   // 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     ?
     46     dead() : dead();
     47   live(),
     48     float
     49       (halt()); // expected-warning {{will never be executed}}
     50 }
     51 
     52 void test4() {
     53   struct S {
     54     int mem;
     55   } s;
     56   S &foor();
     57   halt(), foor()// expected-warning {{will never be executed}}
     58     .mem;
     59 }
     60 
     61 void test5() {
     62   struct S {
     63     int mem;
     64   } s;
     65   S &foor() __attribute__((noreturn));
     66   foor()
     67     .mem;       // expected-warning {{will never be executed}}
     68 }
     69 
     70 void test6() {
     71   struct S {
     72     ~S() { }
     73     S(int i) { }
     74   };
     75   live(),
     76     S
     77       (halt());  // expected-warning {{will never be executed}}
     78 }
     79