A test case added.
Hi rnk,
http://llvm-reviews.chandlerc.com/D2124
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2124?vs=5412&id=5427#toc
Files:
lib/Sema/SemaExpr.cpp
test/Sema/PR10837.c
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10614,6 +10614,15 @@
switch (ConvTy) {
case Compatible:
+ // 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();
+
DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
return false;
Index: test/Sema/PR10837.c
===================================================================
--- /dev/null
+++ test/Sema/PR10837.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+int *p = 0;
+
+int *q = '\0'; // expected-warning{{expression which evaluates to zero
treated as a null pointer constant}}
+
+int *r = (1 - 1); // expected-warning{{expression which evaluates to zero
treated as a null pointer constant}}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10614,6 +10614,15 @@
switch (ConvTy) {
case Compatible:
+ // 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();
+
DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
return false;
Index: test/Sema/PR10837.c
===================================================================
--- /dev/null
+++ test/Sema/PR10837.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+int *p = 0;
+
+int *q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
+
+int *r = (1 - 1); // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits