This patch turns off the tautological compare warnings when one of the
operands is a template parameter type. There's not an easy way to correct
the code or silence this warning so this way seemed to be the best
solution. Anyone have any thoughts on altering the behavior of this
warning?
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp (revision 193715)
+++ lib/Sema/SemaChecking.cpp (working copy)
@@ -4782,6 +4782,9 @@
BinaryOperatorKind op = E->getOpcode();
if (E->isValueDependent())
return;
+ if (isa<SubstTemplateTypeParmType>(E->getLHS()->getType()) ||
+ isa<SubstTemplateTypeParmType>(E->getRHS()->getType()))
+ return;
if (op == BO_LT && IsZero(S, E->getRHS())) {
S.Diag(E->getOperatorLoc(), diag::warn_lunsigned_always_true_comparison)
@@ -4814,6 +4817,9 @@
QualType OtherT = Other->getType();
QualType ConstantT = Constant->getType();
QualType CommonT = E->getLHS()->getType();
+ if (isa<SubstTemplateTypeParmType>(OtherT) ||
+ isa<SubstTemplateTypeParmType>(ConstantT))
+ return;
if (S.Context.hasSameUnqualifiedType(OtherT, ConstantT))
return;
assert((OtherT->isIntegerType() && ConstantT->isIntegerType())
Index: test/SemaCXX/compare.cpp
===================================================================
--- test/SemaCXX/compare.cpp (revision 193715)
+++ test/SemaCXX/compare.cpp (working copy)
@@ -355,3 +355,26 @@
};
(void)((E)x == 1);
}
+
+namespace test10 {
+template<class T> T max();
+template<class T> T min();
+
+template<> constexpr int max<int>() { return 2147483647; };
+
+template<typename T>
+inline bool less_than_max(short num, T value) {
+ const T vmax = max<T>();
+ return (vmax >= num); // no warning
+}
+
+template<typename T>
+inline bool less_than_zero(T num) {
+ return num < 0; // no warning
+}
+
+void test10(short num, int x) {
+ less_than_max(num, x);
+ less_than_zero(unsigned(1));
+}
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits