[cfe-dev] Bug in block parsing

Eli Friedman eli.friedman at gmail.com
Sun Sep 6 15:20:32 PDT 2009


On Sun, Sep 6, 2009 at 11:03 AM, David Yoo<dyoo1 at umiacs.umd.edu> wrote:
> 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




More information about the cfe-dev mailing list