[LLVMbugs] [Bug 24328] New: clang should warn returning nil from Obj-C method that returns nonnull

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 31 10:39:35 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24328

            Bug ID: 24328
           Summary: clang should warn returning nil from Obj-C method that
                    returns nonnull
           Product: new-bugs
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: sean at rogue-research.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 14678
  --> https://llvm.org/bugs/attachment.cgi?id=14678&action=edit
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>.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150731/5651f882/attachment.html>


More information about the llvm-bugs mailing list