Using immutable values as template parameter hangs dmd
Simen Kjaeraas
simen.kjaras at gmail.com
Sun Jun 26 09:15:39 PDT 2011
On Sun, 26 Jun 2011 16:10:04 +0200, simendsjo <simen.endsjo at pandavre.com>
wrote:
> This is probably not a minimal test case, but it's as far as I got.
> Don't know what the actual bug is, so I'd be grateful if someone else
> could help explain it so I can add it to Bugzilla with a better subject.
>
> This is using DMD 2.053 on win7.
>
> struct S(int N) {
> immutable SN = N;
> // Using N instead, and the compiler doesn't hang
> // It doesn't have anything to do with alias. The same occurs in
> method templates etc.
> alias S!SN T;
> }
>
> void main() {
> S!(4) s;
> }
It's a case of infinite recursive templates. My dmd fails after
a few seconds with Error: out of memory, right after semantic3.
Same bug also occurs with const values.
Think I understand what's going on now - the alias tries to instantiate
the template with an immutable int, dmd says 'hey, that's implicitly
convertable to a normal int', and instantiates the template. Now, that
template does not know it is in fact instantiated with an immutable int,
and thus feels S!SN is something different from S!N, and creates a whole
new instantiation when it gets to the alias line. GOTO 10.
--
Simen
More information about the Digitalmars-d-learn
mailing list