Bug in block parsing

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; }

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.

It's a missed warning; please file.

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; \}

Please send a patch to cfe-commits.

-Eli

Chris just fixed this. :slight_smile: