auto
Ary Borenszweig
ary at esperanto.org.ar
Wed Aug 12 07:59:18 PDT 2009
Ary Borenszweig wrote:
> bearophile wrote:
>> Ary Borenszweig:
>>> Since when a non-templated function can have its return type deduced?
>>> :)<
>>
>> More than two months ago I have asked for such feature. Then I have
>> tested it, and it was already present :-) So I think it's OK, and
>> expected, it helps when you return very complex types (for example
>> lazy templated generators).
>
> Ah... but it wasn't mentioned anywhere.
>
> I was asking because I get parser errors with Descent if I write that.
> I'm trying to see where I made a mistake in porting the parser, but the
> code for parsing that is:
>
> ---
> /* Look for return type inference for template functions.
> */
> {
> Token *tk;
> if (storage_class &&
> token.value == TOKidentifier &&
> (tk = peek(&token))->value == TOKlparen &&
> skipParens(tk, &tk) &&
> peek(tk)->value == TOKlparen)
> {
> ts = NULL;
> }
> else
> {
> ts = parseBasicType();
> ts = parseBasicType2(ts);
> }
> }
> ---
>
> and there's also a similar code somewhere else. The parser is there
> after consuming the "auto" token, so token's value is TOKidentifier. As
> you can see, it checks that the next token is "(", then it peeks past
> the closing parenthesis and checks that that token is also "(" (for a
> templated function). So it won't work with non-templated functions. And
> parseBasicType and parseBasicType2 fail.
>
> I'll probably need to debug the C++ code... unless someone can debug it
> for me and tell me what's going on. :)
Heh, debugging the code revealed that also this condition is present:
|| peek(tk)->value == TOKlcurly
so that's why it parses it ok. Ah... mistery solved.
More information about the Digitalmars-d
mailing list