-Wnullable-to-nonnull-conversion not recognizing 'nil' as nullable
| Bugzilla Link | 26664 |
| Version | unspecified |
| OS | MacOS X |
| Reporter | LLVM Bugzilla Contributor |
| CC | @devincoughlin,@AnnaZaks |
Extended Description
CLANG_ANALYZER_NONNULL with Xcode 7.3 Beta 3 is giving incomplete warnings.
Steps to Reproduce:
NSString * _Nonnull foo = nil;
Actual result: no warning Expected result: warning for converting from Nullable to Nonnull.
Workaround: one can define this macro...
#define __DARWIN_NULL ((void * _Nullable)0)
This is tracked internally as rdar://problem/24724255/
There are two separate warnings mentioned here. One is a compiler warning (-Wnullable-to-nonnull-conversion). The other is a static analyzer warning (the nullability checker).
The analyzer does warn here:
$ cat local-nonnull.m #include <Foundation/Foundation.h> void foo() { NSString * _Nonnull foo = nil; (void)foo; }
$ clang --analyze local-nonnull.m local-nonnull.m:4:3: warning: Null is assigned to a pointer which is expected to have non-null value NSString * _Nonnull foo = nil; ^~~~~~~~~~~~~~~~~~~~~~~ ~~~ 1 warning generated.
But the compiler does not:
$ clang -fsyntax-only -Wnullable-to-nonnull-conversion local-nonnull.m
(No warnings).
assigned to @adrian-prantl