summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaChecking.cpp4
-rw-r--r--clang/test/SemaCXX/compare.cpp19
2 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 772fee32ceb..733bd0f9bbf 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4779,6 +4779,10 @@ static bool HasEnumType(Expr *E) {
}
static void CheckTrivialUnsignedComparison(Sema &S, BinaryOperator *E) {
+ // Disable warning in template instantiations.
+ if (!S.ActiveTemplateInstantiations.empty())
+ return;
+
BinaryOperatorKind op = E->getOpcode();
if (E->isValueDependent())
return;
diff --git a/clang/test/SemaCXX/compare.cpp b/clang/test/SemaCXX/compare.cpp
index 22f2565882c..563a15251c3 100644
--- a/clang/test/SemaCXX/compare.cpp
+++ b/clang/test/SemaCXX/compare.cpp
@@ -380,4 +380,23 @@ namespace templates {
less_than_max<long>(num);
less_than_max<short>(num);
}
+
+ template<typename T>
+ inline bool less_than_zero(T num, T value) {
+ return num < 0; // no warning
+ }
+
+ template<typename T>
+ inline bool less_than_zero(unsigned num) {
+ // This should trigger one warning on the template pattern, and not a
+ // warning per specialization.
+ return num < 0; // expected-warning{{comparison of unsigned expression < 0 is always false}}
+ }
+
+ void test11(unsigned num) {
+ less_than_zero(num, num);
+ less_than_zero<int>(num);
+ less_than_zero<long>(num);
+ less_than_zero<short>(num);
+ }
}
OpenPOWER on IntegriCloud