A warning should be displayed when a nullable pointer is used as a nonnull pointer.
| Originator: | nathaniel.chandler | ||
| Number: | rdar://20188572 | Date Originated: | 2015/03/17 |
| Status: | Duplicate of 19003620 | Resolved: | |
| Product: | Developer Tools | Product Version: | 6D543q |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
Presently, clang only produces a diagnostic in the context of a nonnull/__nonnull parameter when nil/NULL is passed as the argument. For example, it will warn in this case:
void takeInt(int * __nonnull f) {
NSLog(@"%p: %d", f, *f);
}
int main(int argc, char *argv[]) {
takeInt(NULL);
}
A warning ("Null passed to a callee that requires a non-null argument") is produced for <<takeInt(NULL);>>. This is great.
It is not, however, as useful as it might be. It would be great to be be warned when passing a nullable pointer as the argument to a nonnull parameter. For example:
int * __nullable makeInt() {
u_int32_t v = arc4random_uniform(5);
if (v) {
int *ptr = calloc(1, sizeof(int));
return ptr;
} else {
return nil;
}
}
void takeInt(int * __nonnull f) {
NSLog(@"%p: %d", f, *f);
}
int main(int argc, char *argv[]) {
int * __nullable ptr = makeInt();
takeInt(ptr);
}
A warning should be produced for <<takeInt(ptr);>>, perhaps something like ("Nullable passed to a callee that requires a non-null argument").
Steps to Reproduce:
Expected Results:
A warning should be produced when a nullable argument is passed to a callee that requires a non-null argument.
Actual Results:
No such warning is produced
Version:
Xcode 6.3 (6D543q)
Notes:
Configuration:
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!