2011-02-28 08:40:07 +08:00
|
|
|
// RUN: %clang_cc1 %s -fcxx-exceptions -fexceptions -fsyntax-only -verify -fblocks -Wunreachable-code -Wno-unused-value
|
2010-01-21 23:20:48 +08:00
|
|
|
|
2010-09-03 08:25:02 +08:00
|
|
|
int &halt() __attribute__((noreturn));
|
2010-01-22 01:21:23 +08:00
|
|
|
int &live();
|
2010-01-21 23:20:48 +08:00
|
|
|
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}}
|
|
|
|
}
|
2010-01-22 01:21:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
void test3() {
|
|
|
|
halt()
|
|
|
|
--; // expected-warning {{will never be executed}}
|
2010-12-16 16:22:16 +08:00
|
|
|
// FIXME: The unreachable part is just the '?', but really all of this
|
|
|
|
// code is unreachable and shouldn't be separately reported.
|
|
|
|
halt() // expected-warning {{will never be executed}}
|
|
|
|
?
|
2010-01-22 03:44:04 +08:00
|
|
|
dead() : dead();
|
2010-01-22 06:12:18 +08:00
|
|
|
live(),
|
2011-07-19 22:18:48 +08:00
|
|
|
float
|
|
|
|
(halt()); // expected-warning {{will never be executed}}
|
2010-01-22 01:21:23 +08:00
|
|
|
}
|
2010-01-22 07:15:53 +08:00
|
|
|
|
|
|
|
void test4() {
|
|
|
|
struct S {
|
|
|
|
int mem;
|
|
|
|
} s;
|
|
|
|
S &foor();
|
2010-02-24 10:19:28 +08:00
|
|
|
halt(), foor()// expected-warning {{will never be executed}}
|
|
|
|
.mem;
|
2010-01-22 07:15:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test5() {
|
|
|
|
struct S {
|
|
|
|
int mem;
|
|
|
|
} s;
|
2013-09-20 09:15:31 +08:00
|
|
|
S &foonr() __attribute__((noreturn));
|
|
|
|
foonr()
|
2010-01-22 07:15:53 +08:00
|
|
|
.mem; // expected-warning {{will never be executed}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test6() {
|
|
|
|
struct S {
|
|
|
|
~S() { }
|
|
|
|
S(int i) { }
|
|
|
|
};
|
|
|
|
live(),
|
2011-07-19 22:18:48 +08:00
|
|
|
S
|
|
|
|
(halt()); // expected-warning {{will never be executed}}
|
2010-01-22 07:15:53 +08:00
|
|
|
}
|
2011-12-01 05:22:09 +08:00
|
|
|
|
|
|
|
// Don't warn about unreachable code in template instantiations, as
|
|
|
|
// they may only be unreachable in that specific instantiation.
|
|
|
|
void isUnreachable();
|
|
|
|
|
|
|
|
template <typename T> void test_unreachable_templates() {
|
|
|
|
T::foo();
|
|
|
|
isUnreachable(); // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestUnreachableA {
|
|
|
|
static void foo() __attribute__((noreturn));
|
|
|
|
};
|
|
|
|
struct TestUnreachableB {
|
|
|
|
static void foo();
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_unreachable_templates_harness() {
|
|
|
|
test_unreachable_templates<TestUnreachableA>();
|
|
|
|
test_unreachable_templates<TestUnreachableB>();
|
|
|
|
}
|
|
|
|
|
2011-12-01 08:59:17 +08:00
|
|
|
// Do warn about explict template specializations, as they represent
|
|
|
|
// actual concrete functions that somebody wrote.
|
|
|
|
|
|
|
|
template <typename T> void funcToSpecialize() {}
|
|
|
|
template <> void funcToSpecialize<int>() {
|
|
|
|
halt();
|
|
|
|
dead(); // expected-warning {{will never be executed}}
|
|
|
|
}
|
2012-01-24 12:29:27 +08:00
|
|
|
|
2014-03-05 05:41:38 +08:00
|
|
|
// Handle 'try' code dominating a dead return.
|
|
|
|
enum PR19040_test_return_t
|
|
|
|
{ PR19040_TEST_FAILURE };
|
|
|
|
namespace PR19040_libtest
|
|
|
|
{
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
~A ();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
PR19040_test_return_t PR19040_fn1 ()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw PR19040_libtest::A ();
|
|
|
|
} catch (...)
|
|
|
|
{
|
|
|
|
return PR19040_TEST_FAILURE;
|
|
|
|
}
|
|
|
|
return PR19040_TEST_FAILURE; // expected-warning {{will never be executed}}
|
|
|
|
}
|
|
|
|
|
2014-03-06 14:50:46 +08:00
|
|
|
__attribute__((noreturn))
|
|
|
|
void raze();
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template<typename T> struct basic_string {
|
|
|
|
basic_string(const T* x) {}
|
|
|
|
~basic_string() {};
|
|
|
|
};
|
|
|
|
typedef basic_string<char> string;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string testStr() {
|
|
|
|
raze();
|
|
|
|
return ""; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string testStrWarn(const char *s) {
|
|
|
|
raze();
|
|
|
|
return s; // expected-warning {{will never be executed}}
|
|
|
|
}
|
|
|
|
|
2014-03-05 05:41:38 +08:00
|
|
|
|