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

Richard Smith richard at metafoo.co.uk
Tue Nov 12 11:46:22 PST 2013


  LGTM with minor changes.


================
Comment at: lib/Sema/SemaExpr.cpp:10617-10624
@@ -10616,3 +10616,10 @@
   case Compatible:
-      DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
-      return false;
+    // 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)
+        << DstType << SrcExpr->getSourceRange();
+
----------------
Indentation within the `if (...)` is a bit unusual. Please clang-format this prior to checkin.

================
Comment at: test/Sema/PR10837.c:1
@@ +1,2 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
----------------
Please give this test file a better name. Maybe warn-null.c?


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



More information about the cfe-commits mailing list