[cfe-commits] r71405 - in /cfe/trunk: include/clang/AST/ include/clang/Frontend/ include/clang/Parse/ lib/AST/ lib/CodeGen/ lib/Frontend/ lib/Parse/ lib/Sema/ test/SemaCXX/ www/

Chris Lattner clattner at apple.com
Mon May 11 12:50:51 PDT 2009


On May 10, 2009, at 11:38 AM, Sebastian Redl wrote:
Implement C++0x nullptr.

> // 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
> @@ -431,6 +434,9 @@
>       Width = Target.getLongDoubleWidth();
>       Align = Target.getLongDoubleAlign();
>       break;
> +    case BuiltinType::NullPtr:
> +      Width = Target.getPointerWidth(0); // C++ 3.9.1p11:  
> sizeof(nullptr_t)
> +      Align = Target.getPointerAlign(0); //   == sizeof(void*)
>     }
>     break;

Hi Sebastian,

Though not strictly needed, please do add an explicit break to this  
case.

+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun May 10 13:38:11 2009
@@ -3811,6 +3811,20 @@
     ImpCastExprToType(rex, lType); // promote the pointer to pointer
     return ResultTy;
   }
+  // C++ allows comparison of pointers with null pointer constants.
+  if (getLangOptions().CPlusPlus) {
+    if (lType->isPointerType() && RHSIsNull) {
+      ImpCastExprToType(rex, lType);
+      return ResultTy;
+    }
+    if (rType->isPointerType() && LHSIsNull) {
+      ImpCastExprToType(lex, rType);
+      return ResultTy;
+    }
+    // And comparison of nullptr_t with itself.
+    if (lType->isNullPtrType() && rType->isNullPtrType())
+      return ResultTy;
+  }

Can't this be handled by making isNullPointerConstant handle this?  If  
so, LHSIsNull/RHSIsNull are already computed.

-Chris




More information about the cfe-commits mailing list