Simple hack to do unreachable code analysis on template patterns.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148774 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp
index f36300a..3d36875 100644
--- a/test/SemaCXX/warn-unreachable.cpp
+++ b/test/SemaCXX/warn-unreachable.cpp
@@ -98,6 +98,24 @@
test_unreachable_templates<TestUnreachableB>();
}
+// Do warn about non-dependent unreachable code in templates
+// Warn even if the template is never instantiated
+
+template<typename T> void test_non_dependent_unreachable_templates() {
+ TestUnreachableA::foo();
+ isUnreachable(); // expected-warning {{will never be executed}}
+}
+
+// Warn only once even if the template is instantiated multiple times
+
+template<typename T> void test_non_dependent_unreachable_templates2() {
+ TestUnreachableA::foo();
+ isUnreachable(); // expected-warning {{will never be executed}}
+}
+
+template void test_non_dependent_unreachable_templates2<int>();
+template void test_non_dependent_unreachable_templates2<long>();
+
// Do warn about explict template specializations, as they represent
// actual concrete functions that somebody wrote.
@@ -106,4 +124,3 @@
halt();
dead(); // expected-warning {{will never be executed}}
}
-