[PATCH] Fix to PR10837 - Warn when assigning null character to pointer

Reid Kleckner rnk at google.com
Mon Nov 11 17:51:23 PST 2013



================
Comment at: test/Sema/PR10837.c:1
@@ +1,2 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
----------------
This shouldn't need -pedantic?

================
Comment at: lib/Sema/SemaExpr.cpp:10626-10627
@@ -10617,3 +10625,4 @@
+
       DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
       return false;
 
----------------
This indentation is wrong and should be fixed once you add the if.

================
Comment at: lib/Sema/SemaExpr.cpp:10618-10622
@@ +10617,7 @@
+    // See if a proper null pointer constant is to be assigned.
+    if (DstType->isAnyPointerType() &&
+         !SrcType->isAnyPointerType() &&
+         SrcExpr->isNullPointerConstant(Context,
+           Expr::NPC_NeverValueDependent) == Expr::NPCK_ZeroExpression &&
+        !isUnevaluatedContext())
+      Diag(SrcExpr->getExprLoc(), diag::warn_non_literal_null_pointer)
----------------
I want to punt this condition over to Richard.  NPCK_ZeroExpression seems to me like the correct thing to warn on.


http://llvm-reviews.chandlerc.com/D2124



More information about the cfe-commits mailing list