[LLVMbugs] [Bug 18392] New: False positive: Clang warns about unhanded switch values even if they are handled elsewhere

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jan 5 14:39:15 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=18392

            Bug ID: 18392
           Summary: False positive: Clang warns about unhanded switch
                    values even if they are handled elsewhere
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: razielim at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Clang warns that a switch statement does not handle all enumeration values even
if the values not handled are actually handled elsewhere before the switch
statement.

e.g:

typedef NS_ENUM( NSUInteger, AnEnum ) {
    AnEnumA,
    AnEnumB,
    AnEnumC
};

- (void)doSomething: (AnEnum)value {

    if( AnEnumA == value )
    {
        // Do something special.
    }
    else
    {
        NSUInteger aParam;

        switch( value )
        {
            case AnEnumB: aParam = 1; break;
            case AnEnumC: aParam = 2; break;
        }

        [self doSomethingElse: aParam];
    }
}

Clang warns that the switch statement does not cover 'AnEnumA', even though it
is not possible that value could possibly be 'AnEnumA' at that point.

As you can see, I've stuck AnEnumB and AnEnumC inside a switch statement
because all of those cases are handled the same way (save for a single
parameter value). AnEnumA requires some special treatment, which is why I have
handled it before reaching the switch statement.

-- 
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/20140105/1d4bc795/attachment.html>


More information about the llvm-bugs mailing list