www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Internal error with templates

reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
I was trying to figure out how to use templates with alias parameters
and i wasn't able to figure it out, but i got this internal error

Internal error: ..\ztc\out.c 1127

with this code:

import std.stream;
import std.c.stdio;

alias std.stream.stdout stdout;

template Foo(alias T)
{
 void Foo()
 {
  stdout.writeLine(T);
 }
}

int main ( char [] [] args )
{
 char[] x = "hello";

 alias Foo!(x) fooinst;
 Foo!(x)();

 return 1;
}
May 02 2004
parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
In this code:

<CODE>
import std.stream;
import std.c.stdio;

alias std.stream.stdout stdout;

template Foo(alias T)
{
 void Foo()
 {
  stdout.writeLine(toString(T));
 }
}

int main ( char [] [] args )
{
 static char[] x = "hello";
 static char[] z = "world";
 static int y=100;

 alias Foo!(x) foox;
 alias Foo!(y) fooy;

 Foo!(x)();
 Foo!(y)();
 Foo!(z)();
 foox();
 fooy();

 return 1;
}
</CODE>

I get "Internal error: ..\ztc\out.c 1127"
if instead of "static int y=100;" i write "int y=100;"

But i don't understand the behaviour of the above code!
Why does this code print "hello" five times?

I expected it to print:
hello
100
world
hello
100

What am i missing?

"Ivan Senji" <ivan.senji public.srce.hr> wrote in message
news:c73l45$2df6$1 digitaldaemon.com...
 I was trying to figure out how to use templates with alias parameters
 and i wasn't able to figure it out, but i got this internal error

 Internal error: ..\ztc\out.c 1127

 with this code:

 import std.stream;
 import std.c.stdio;

 alias std.stream.stdout stdout;

 template Foo(alias T)
 {
  void Foo()
  {
   stdout.writeLine(T);
  }
 }

 int main ( char [] [] args )
 {
  char[] x = "hello";

  alias Foo!(x) fooinst;
  Foo!(x)();

  return 1;
 }
May 03 2004
parent reply Craig Pennington <cpenning milo.org> writes:
Ivan Senji wrote:
[snip code]
 I get "Internal error: ..\ztc\out.c 1127"
 if instead of "static int y=100;" i write "int y=100;"
I don't get an error, but the assignment doesn't happen without the static keyword. I am one version behind on dmd and I think I am up to date with dgc, both running on linux.
 But i don't understand the behaviour of the above code!
 Why does this code print "hello" five times?
 I expected it to print:
 hello
 100
 world
 hello
 100
This is what I get with both dmd and dgc using your code. When I drop the 'static' keyword from the int declaration, '100' is replaced by '0'. Then if I do a seperate assignment, that works either way. i.e. <CODE> ... int y; y=100; ... </CODE> works as expected.
 What am i missing?
I am not sure. [remainder snipped] Cheers, Craig
May 05 2004
parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Craig Pennington" <cpenning milo.org> wrote in message
news:c7ak76$pst$1 digitaldaemon.com...
 Ivan Senji wrote:
 [snip code]
 I get "Internal error: ..\ztc\out.c 1127"
 if instead of "static int y=100;" i write "int y=100;"
I don't get an error, but the assignment doesn't happen without the static keyword. I am one version behind on dmd and I think I am up to date with dgc, both running on linux.
Then it is probbably a 0.86 bug, Walter fixed it!
 But i don't understand the behaviour of the above code!
 Why does this code print "hello" five times?
 I expected it to print:
 hello
 100
 world
 hello
 100
This is what I get with both dmd and dgc using your code. When I drop the 'static' keyword from the int declaration, '100' is replaced by '0'. Then if I do a seperate assignment, that works either way. i.e. <CODE> ... int y; y=100; ... </CODE> works as expected.
What does it print when you run it? All i get is: hello hello hello hello hello
 What am i missing?
I am not sure. [remainder snipped] Cheers, Craig
May 05 2004