diff options
Diffstat (limited to 'test/SemaCXX/warn-unreachable.cpp')
-rw-r--r-- | test/SemaCXX/warn-unreachable.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp new file mode 100644 index 0000000..a7ed91d --- /dev/null +++ b/test/SemaCXX/warn-unreachable.cpp @@ -0,0 +1,76 @@ +// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value + +int &halt() __attribute__((noreturn)); +int &live(); +int dead(); +int liveti() throw(int); +int (*livetip)() throw(int); + +int test1() { + try { + live(); + } catch (int i) { + live(); + } + return 1; +} + +void test2() { + try { + live(); + } catch (int i) { + live(); + } + try { + liveti(); + } catch (int i) { + live(); + } + try { + livetip(); + } catch (int i) { + live(); + } + throw 1; + dead(); // expected-warning {{will never be executed}} +} + + +void test3() { + halt() + --; // expected-warning {{will never be executed}} + halt() + ? // expected-warning {{will never be executed}} + dead() : dead(); + live(), + float // expected-warning {{will never be executed}} + (halt()); +} + +void test4() { + struct S { + int mem; + } s; + S &foor(); + halt(), foor() + .mem; // expected-warning {{will never be executed}} +} + +void test5() { + struct S { + int mem; + } s; + S &foor() __attribute__((noreturn)); + foor() + .mem; // expected-warning {{will never be executed}} +} + +void test6() { + struct S { + ~S() { } + S(int i) { } + }; + live(), + S // expected-warning {{will never be executed}} + (halt()); +} |