Template expansion bug?

Steven Schveighoffer schveiguy at yahoo.com
Fri May 31 10:30:45 PDT 2013


On Fri, 31 May 2013 13:18:13 -0400, Simen Kjaeraas  
<simen.kjaras at gmail.com> wrote:

> On 2013-05-31, 16:42, Steven Schveighoffer wrote:
>
>> While doing some testing, I came across this behavior:
>>
>> template foo(T) {
>>      void foo() {}
>> }
>>
>> void main()
>> {
>>      foo!(int).foo();
>>      //foo!(int)(); // this works
>> }
>
> I'm not certain, but it could be ambiguity:
>
> template foo(T) {
>      struct foo {
>          T foo;
>      }
> }
>
> auto bar = foo!int.foo; // Is bar an int or a foo!int struct?

This is true, but there is an implicit call going on in the function  
version.

Incidentally, testing shows that foo!int.foo in your case is the int, not  
the struct.

Renaming the foo member to foox, it now complains similarly (can't find  
member foo, did you mean foox?).

It appears that the expanded version of eponymous templates is pretty much  
disabled at this point.  I'm not sure this is a bad thing, but it should  
at least be documented.  I'm pretty sure this used to work, but I'd have  
to download an old version of DMD to figure that out :)

-Steve


More information about the Digitalmars-d mailing list