Hi rnk,
This patch solves the request for adding a diagnostic for assignmets and
initialization by "improper" null pointer constants in C.
http://llvm.org/bugs/show_bug.cgi?id=10837
http://llvm-reviews.chandlerc.com/D2124
Files:
lib/Sema/SemaExpr.cpp
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: 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;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits