[cfe-commits] r126057 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/compare.cpp test/SemaCXX/type-dependent-exprs.cpp

Douglas Gregor dgregor at apple.com
Sat Feb 19 14:34:59 PST 2011


Author: dgregor
Date: Sat Feb 19 16:34:59 2011
New Revision: 126057

URL: http://llvm.org/viewvc/llvm-project?rev=126057&view=rev
Log:
Don't produce "comparison is always (true|false)" warnings when the
comparison itself is a constant expression. Fixes PR7536.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaCXX/compare.cpp
    cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=126057&r1=126056&r2=126057&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Feb 19 16:34:59 2011
@@ -2581,7 +2581,11 @@
   // We don't do anything special if this isn't an unsigned integral
   // comparison:  we're only interested in integral comparisons, and
   // signed comparisons only happen in cases we don't care to warn about.
-  if (!T->hasUnsignedIntegerRepresentation())
+  //
+  // We also don't care about value-dependent expressions or expressions
+  // whose result is a constant.
+  if (!T->hasUnsignedIntegerRepresentation()
+      || E->isValueDependent() || E->isIntegerConstantExpr(S.Context))
     return AnalyzeImpConvsInComparison(S, E);
 
   Expr *lex = E->getLHS()->IgnoreParenImpCasts();

Modified: cfe/trunk/test/SemaCXX/compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=126057&r1=126056&r2=126057&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/compare.cpp Sat Feb 19 16:34:59 2011
@@ -206,3 +206,9 @@
   if (vp < 0) { }
   if (test1 < e) { } // expected-error{{comparison between pointer and integer}}
 }
+
+// PR7536
+static const unsigned int kMax = 0;
+int pr7536() {
+  return (kMax > 0);
+}

Modified: cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp?rev=126057&r1=126056&r2=126057&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp Sat Feb 19 16:34:59 2011
@@ -26,10 +26,10 @@
 // This one entered into an infinite loop.
 template <unsigned long N>
 void rdar8520617() {
-  if (N > 1) { } // expected-warning {{comparison of 0 > unsigned expression is always false}}
+  if (N > 1) { }
 }
 
 int f2() {
-  rdar8520617<0>(); // expected-note {{in instantiation}}
+  rdar8520617<0>();
 }
 





More information about the cfe-commits mailing list