Identifier (...) is too long by X characters
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Wed Jul 12 14:11:56 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. 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.
>
>
>> 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.
>
>
The compiler does always evaluate "lazily", and that is documented,
although it may not be immediately obvious:
The template spec states that "Semantic analysis is not done until
instantiated." which in other words means a template is not evaluated
until instantiated. This remains true for nested templates, and thus for
your example as well.
Then why the error message? My guess is that the error message is simply
a mistake on part of the compiler, where the recursive template
detection system gives a false positive (it thinks it will expand
indefinitely but it won't). Thus it is a bug.
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-bugs
mailing list