Don't run -Wunreachable-code on template instantiations. Different instantiations may produce different unreachable code results, and it is very difficult for us to prove that ALL instantiations of a template have specific unreachable code. If we come up with a better solution, then we can revisit this, but this approach will at least greatly reduce the noise of this warning for code that makes use of templates.

llvm-svn: 145520
This commit is contained in:
Ted Kremenek 2011-11-30 21:22:09 +00:00
parent a0c69014f8
commit 7f770032c7
2 changed files with 30 additions and 2 deletions

View File

@ -914,8 +914,14 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
}
// Warning: check for unreachable code
if (P.enableCheckUnreachable)
CheckUnreachable(S, AC);
if (P.enableCheckUnreachable) {
// Only check for unreachable code on non-template instantiations.
// Different template instantiations can effectively change the control-flow
// and it is very difficult to prove that a snippet of code in a template
// is unreachable for all instantiations.
if (S.ActiveTemplateInstantiations.empty())
CheckUnreachable(S, AC);
}
// Check for thread safety violations
if (P.enableThreadSafetyAnalysis) {

View File

@ -76,3 +76,25 @@ void test6() {
S
(halt()); // expected-warning {{will never be executed}}
}
// 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>();
}