[cfe-commits] r118234 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/nullptr.cpp

Anders Carlsson andersca at mac.com
Wed Nov 3 20:17:43 PDT 2010


Author: andersca
Date: Wed Nov  3 22:17:43 2010
New Revision: 118234

URL: http://llvm.org/viewvc/llvm-project?rev=118234&view=rev
Log:
It's OK to use nullptr in relational operators if the other side is a null pointer constant.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/nullptr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=118234&r1=118233&r2=118234&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Nov  3 22:17:43 2010
@@ -5735,6 +5735,7 @@
           return ResultTy;
         }
       }
+
       // C++ [expr.rel]p2:
       //   [...] Pointer conversions (4.10) and qualification
       //   conversions (4.4) are performed on pointer operands (or on
@@ -5788,10 +5789,14 @@
   }
 
   if (getLangOptions().CPlusPlus) {
+    // Comparison of nullptr_t with itself.
+    if (lType->isNullPtrType() && rType->isNullPtrType())
+      return ResultTy;
+    
     // Comparison of pointers with null pointer constants and equality
     // comparisons of member pointers to null pointer constants.
     if (RHSIsNull &&
-        (lType->isPointerType() ||
+        ((lType->isPointerType() || lType->isNullPtrType()) ||
          (!isRelational && lType->isMemberPointerType()))) {
       ImpCastExprToType(rex, lType, 
                         lType->isMemberPointerType()
@@ -5800,7 +5805,7 @@
       return ResultTy;
     }
     if (LHSIsNull &&
-        (rType->isPointerType() ||
+        ((rType->isPointerType() || rType->isNullPtrType()) ||
          (!isRelational && rType->isMemberPointerType()))) {
       ImpCastExprToType(lex, rType, 
                         rType->isMemberPointerType()
@@ -5840,10 +5845,6 @@
       ImpCastExprToType(rex, T, CK_BitCast);
       return ResultTy;
     }
-
-    // Comparison of nullptr_t with itself.
-    if (lType->isNullPtrType() && rType->isNullPtrType())
-      return ResultTy;
   }
 
   // Handle block pointer types.

Modified: cfe/trunk/test/SemaCXX/nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr.cpp?rev=118234&r1=118233&r2=118234&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/nullptr.cpp (original)
+++ cfe/trunk/test/SemaCXX/nullptr.cpp Wed Nov  3 22:17:43 2010
@@ -38,6 +38,10 @@
   (void)((void*)0 == nullptr);
   (void)(null <= (void*)0);
   (void)((void*)0 <= nullptr);
+  (void)(0 == nullptr);
+  (void)(nullptr == 0);
+  (void)(nullptr <= 0);
+  (void)(0 <= nullptr);
   (void)(1 > nullptr); // expected-error {{invalid operands to binary expression}}
   (void)(1 != nullptr); // expected-error {{invalid operands to binary expression}}
   (void)(1 + nullptr); // expected-error {{invalid operands to binary expression}}





More information about the cfe-commits mailing list