<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW " title="NEW --- - clang should warn returning nil from Obj-C method that returns nonnull" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24328&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=2bEuhs2nwxXo3XEomafhKbslen5YYlurdyNg5xBy0nc&s=Id1gVyXanFAbUsGBBVh-yGkp_oOgQGVq4TgZ3xCMvbs&e=">24328</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang should warn returning nil from Obj-C method that returns nonnull
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sean@rogue-research.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=14678" name="attach_14678" title="repro case">attachment 14678</a> <a href="attachment.cgi?id=14678&action=edit" title="repro case">[details]</a></span>
repro case
clang warns if a C function with "nonnull" specified on the return value
actually does returns null. That's good. It should, but doesn't, do the same
for Obj-C methods.
Consider attached sample:
-----------------------------------------------
#import <Foundation/Foundation.h>
@interface MyObj : NSObject
@end
@implementation MyObj
+ (nonnull id)method
{
return nil; // WANT WARNING HERE
}
@end
static void* __nonnull MyFunction (void)
{
return NULL;
}
int main(void)
{
MyFunction();
[MyObj method];
return 0;
}
-----------------------------------------------
built with:
clang version 3.8.0 (trunk 243643)
Target: x86_64-apple-darwin14.4.0
Thread model: posix
clang -fsyntax-only -Weverything test.m
gives:
test.m:15:2: warning: null returned from function that requires a non-null
return value [-Wnonnull]
return NULL;
^ ~~~~
ie, works for function, but not method.
(Xcode 6.4 and 7.0b4 clang also fail to warn, see <rdar://22093658>.)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>