[Issue 14719] Template instantiation parsed as C-style type cast

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jun 22 09:52:51 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14719

--- Comment #2 from Yuxuan Shui <yshuiv7 at gmail.com> ---
(In reply to Kenji Hara from comment #1)
> (In reply to Yuxuan Shui from comment #0)
> > (a!A)!B
> >
> > Which is parsed as a C-style cast.
> 
> It's not a bug. The code is parsed as:
> 
> (a!A)    // a type name a!A with parenthesis
> !        // unary operator !
> B        // an identifier B
> 
> so `(typename) expr` makes a C-style cast.
> 
> To do what you want, you need to write:
> 
> alias aA = a!A;
> aA!B

OK, that makes sense.

Butthis(In reply to Kenji Hara from comment #1)
> (In reply to Yuxuan Shui from comment #0)
> > (a!A)!B
> >
> > Which is parsed as a C-style cast.
> 
> It's not a bug. The code is parsed as:
> 
> (a!A)    // a type name a!A with parenthesis
> !        // unary operator !
> B        // an identifier B
> 
> so `(typename) expr` makes a C-style cast.
> 
> To do what you want, you need to write:
> 
> alias aA = a!A;
> aA!B

Well that makes sense. But I still don't think this is the right way.

First, (a!A) is not always a type, it can be a function or anything. Second, B
is a type, so parse !B as expression is weird.
 And this makes instantiate nested templates hard.

--


More information about the Digitalmars-d-bugs mailing list