[llvm-bugs] [Bug 25294] New: Cannot jump to switch label when using blocks and ARC

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 23 02:26:51 PDT 2015


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

            Bug ID: 25294
           Summary: Cannot jump to switch label when using blocks and ARC
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: warp at iki.fi
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

clang reports version: Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0

Consider the following code:

//-----------------------------------------------------------
int foo(int i)
{
    NSString* str = [NSString new];
    int(^func)() = nil;
    switch(i)
    {
      case 0: func = ^{ return (int)str.length; }; break;
      case 1: func = ^{ return (int)str.length; }; break;
    }
    return func();
}
//-----------------------------------------------------------

When compiling with ARC enabled, it gives the following error:

test.m:10:7: error: cannot jump from switch statement to this case label
      case 1: func = ^{ return (int)str.length; }; break;
      ^
test.m:5:15: note: jump enters lifetime of block which strongly captures a
variable
    NSString* str = [NSString new];

Note that these functions do not cause an error:

//-----------------------------------------------------------
int foo2(int i)
{
    int value = i * 2;
    int(^func)() = nil;
    switch(i)
    {
      case 0: func = ^{ return value * 2; }; break;
      case 1: func = ^{ return value * 3; }; break;
    }
    return func();
}

int(^foo3(int i))()
{
    NSString* str = [NSString new];
    switch(i)
    {
      case 0: return ^{ return (int)str.length; };
      case 1: return ^{ return (int)str.length; };
    }
    return 0;
}
//-----------------------------------------------------------

-- 
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/20151023/549e0ecd/attachment-0001.html>


More information about the llvm-bugs mailing list