[cfe-dev] Bug in block parsing

David Yoo dyoo1 at umiacs.umd.edu
Sun Sep 6 11:03:20 PDT 2009


Normally, compiling a function that returns a block that references  
stack variables, such as:

int (^stack_block(void))(void)
{
     int stack_var;
     return ^{ return stack_var; };
}

...will fail with "error: returning block that lives on the local  
stack," which is desired. However, wrapping the return statement in  
parentheses will suppress this error and compile in clang (both  
release and repository):

     return (^{ return stack_var; });

gcc 4.2.1's error message is unaffected by the added parentheses.


On a small unrelated matter, the BlockLanguageSpec gives some examples  
for block literal declarations, including the following:

     typedef int (*pointerToFunctionThatReturnsIntWithCharArg)(char);
     pointerToFunctionThatReturnsIntWithCharArg functionPointer;

     ^ pointerToFunctionThatReturnsIntWithCharArg (float x) { return  
functionPointer; }
     ^ int ((*)(float x))(char) { return functionPointer; }

...where the two blocks should be synonymous. This doesn't appear to  
be the case; the second declaration should be:

     ^ int (*(float x))(char) { return functionPointer; }



More information about the cfe-dev mailing list