[cfe-commits] [PATCH] Parsing C++0x lambda expressions
Sean Hunt
scshunt at csclub.uwaterloo.ca
Fri Jul 29 19:43:13 PDT 2011
On Fri, Jul 29, 2011 at 19:29, David Blaikie <dblaikie at gmail.com> wrote:
>> I forgot to add that the latest patch adds a call to the new lambda
>> parsing function, and one of the tests breaks:
>> Parser/cxx0x-attributes.cpp. On line 20, attribute syntax ("[[]]") is
>> used where an expression is expected.
>
> Actually it's a bit more nuanced than that - line 20 is
>
> void after_const_attr () const [[]];
>
> the [ is valid at parse time - that would be the start of declaring a
> function that returns an array (which is illegal, but I assume that
> it's just easier to parse this in a unified way & pick it up in
> semantic analysis). Of course the thing inside the [] has to be an
> expression - in this case it was yet more [], trying to be parsed as
> an expression. Well now [ is a valid way to start an expression, so
> the error is slightly different.
>
>> Consequently, instead of
>> generating the expected error ("expected expression"), two errors
>> related to lambda parsing are generated. The first comes from the lambda
>> parsing function, and the second comes after lambda parsing returns
>> ExprEmpty(). How should this be handled?
>
> Since the lambda parser succeeded at parsing this as an expression,
> the parser progressed (or the semantic analysis - I didn't check where
> the second message came from) & found that void wasn't a sensible
> element type to try to return an array of from a function.
>
> Should we fail to parse this entirely at the moment? (so we don't get
> the second error) Eventually we could suggest fixups for this error
> (simply adding {} is probably the only thing we can really guess).
>
> [& I'm going to try adding some more (negative & positive) test cases
> as per Doug's request/suggestion now]
(error: expected ' or ] after &) :P
The standard prohibits [[ in any case that isn't to introduce an
attribute ([decl.attr.grammar]/6) to avoid the need for
headache-inducing tentative parsing. We should fail this parse.
Sean
More information about the cfe-commits
mailing list