r193888 - Disable -Wtautological-compare in template instantiations.
Richard Trieu
rtrieu at google.com
Fri Nov 1 14:47:19 PDT 2013
Author: rtrieu
Date: Fri Nov 1 16:47:19 2013
New Revision: 193888
URL: http://llvm.org/viewvc/llvm-project?rev=193888&view=rev
Log:
Disable -Wtautological-compare in template instantiations.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/compare.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=193888&r1=193887&r2=193888&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Nov 1 16:47:19 2013
@@ -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;
Modified: cfe/trunk/test/SemaCXX/compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=193888&r1=193887&r2=193888&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/compare.cpp Fri Nov 1 16:47:19 2013
@@ -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);
+ }
}
More information about the cfe-commits
mailing list