[llvm-bugs] [Bug 30804] New: Storing nullable values to local variables defeats -Wnullable-to-nonnull-conversion

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 26 16:42:10 PDT 2016


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

            Bug ID: 30804
           Summary: Storing nullable values to local variables defeats
                    -Wnullable-to-nonnull-conversion
           Product: clang
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tjw at me.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 17499
  --> https://llvm.org/bugs/attachment.cgi?id=17499&action=edit
sample case

Adding nullability annotations to ObjC source for correct interoperability with
Swift is made more difficult by the inability of clang to detect if a method
might return nil even if it says it doesn't.

clang apparently has a -Wnullable-to-nonnull-conversion flag to detect cases
like this. While it works for code like:

- (nonnull NSString *)ok:(nullable NSString *)arg;
{
    return arg;    
}

it is trivially confused by:

- (nonnull NSString *)bad:(nullable NSString *)arg;
{
    // BAD: nullable value returned to a non-nullable result
    NSString *result = arg;
    return result;    
}

Example file attached with a couple variants.

-- 
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/20161026/d24e9878/attachment-0001.html>


More information about the llvm-bugs mailing list