diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-11-30 21:22:09 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-11-30 21:22:09 +0000 |
commit | 5dfee06daa359bbe0f3c9de055b8a02d61a05173 (patch) | |
tree | 2ad77a4bd7ba8c31c073121306f80d9b5156008e | |
parent | e25633f777cfcaa564b4ed36cec37d6e6e1ecb04 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145520 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 10 | ||||
-rw-r--r-- | test/SemaCXX/warn-unreachable.cpp | 22 |
2 files changed, 30 insertions, 2 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 8b2e269708..54a26b3253 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -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) { diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index 604a3c0da3..fa740bac65 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -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>(); +} + |