[PATCH] D22391: [Sema] Add warning for implicitly casting a null constant to a non null pointer type
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 16 11:19:14 PDT 2018
ahatanak added inline comments.
================
Comment at: test/Sema/conditional-expr.c:20
vp = 0 ? (double *)0 : (void *)0;
- ip = 0 ? (double *)0 : (void *)0; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}}
+ ip = 0 ? (double *)0 : (void *)0; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double * _Nullable'}}
----------------
ahatanak wrote:
> jordan_rose wrote:
> > This seems like an unfortunate change to make, since most people do not bother with nullability.
> Yes, this is unfortunate, but I'm not sure what's the right way to avoid printing nullability specifiers in the diagnostic message. Do you have any suggestions?
It looks like I can use PrintingPolicy to print the nullability specifier only when needed.
I think it's also possible to add a flag to Expr that indicates the Expr is possibly null. For example, when an Expr is an IntegerLiteral of value 0, or a CastExpr or a ConditionalOperator has a subexpression whose flag is set. This could be a better solution than the current solution in this patch.
Repository:
rC Clang
https://reviews.llvm.org/D22391
More information about the cfe-commits
mailing list