[PATCH] D22391: [Sema] Add warning for implicitly casting a null constant to a non null pointer type
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 14 17:56:43 PDT 2016
ahatanak created this revision.
ahatanak added a reviewer: doug.gregor.
ahatanak added a subscriber: cfe-commits.
This patch makes clang issue a warning when a null constant is used in a context where a non null expression is expected. For example:
```
int * _Nonnull p0 = 0; // warning expected here
int * _Nonnull p1;
int * _Nonnull p2 = c ? p1 : 0; // warning expected here
```
A new function Sema::diagnoseNullPtrToNonnullCast is defined, which checks whether a null pointer constant is being cast to a _Nonnull pointer type, and called before ImplicitCastExprs are created.
rdar://problem/24724255
rdar://problem/22074116
https://reviews.llvm.org/D22391
Files:
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/Sema.cpp
lib/Sema/SemaExpr.cpp
test/Sema/nullability.c
test/SemaCXX/nullability.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22391.64070.patch
Type: text/x-patch
Size: 7519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160715/8490dd4c/attachment.bin>
More information about the cfe-commits
mailing list