Identifier (...) is too long by X characters

Sean Kelly sean at f4.ca
Mon Jul 10 09:42:27 PDT 2006


Tom S wrote:
> Sean Kelly wrote:
>> I don't know.  To do so would be like allowing:
>>
>> struct S
>> {
>>     S val;
>> }
> 
> Umm... not quite. In your case it's just a plain nested, recursive 
> struct which is obviously impossible. In my case:
> 
> struct Foo(T) {
>     Foo!(Foo!(T)) rec()() {
>         Foo!(Foo!(T)) res;
>         return res;
>     }
> }
> 
> When the function template is instantiated, one more nesting level is 
> 'added' and a non-recurring struct is returned.

Oops, you're right.  I should have looked at the example more closely.

 > The compiler reports an
> error because somehow it doesn't instantiate the 'rec' template lazily. 
> In the example you've given there's an infinite theoretical nesting, yet 
> in the version with the function, infinite nesting isn't possible, 
> because the nesting increases one level with each 'rec' instantiation. 
> IIRC, that's perfectly legit in C++ as it uses a different method for 
> template instantiation.

Yeah.  I think the problem in D is that all template members are 
explicitly instantiated together instead of on an as-needed basis.  But 
as rec() is itself a template function I wouldn't have expected this 
behavior.  I agree that this should be changed, assuming it's possible 
to do so without entirely changing the way templates are instantiated in D.

>> I'm not sure I'd want the compiler to try and "fix" a mistake I'd made 
>> involving this.  Adding an integer is pretty easy anyway.
> 
> Easy ? It's undocumented, tedious and generally weird. It might stop 
> working in the next compiler version because I'm not even sure why DMD 
> allows it.

You're right.  Sorry for the confusion.


Sean



More information about the Digitalmars-d-bugs mailing list