www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - array initialization in template

reply tetsuya <tetsuya_member pathlink.com> writes:
dmd 1.04, winXP

looks like the initialization of an array in a class
in a template is missing...

try this code.

<code>
template Foo(T, int L)
{
T[L] arr;
class Bar { T[L] arr; }
}

unittest
{
alias Foo!(int, 100) foo;

foreach (int x; foo.arr)
assert(x == int.init);	// initialized, no problem

foo.Bar bar = new foo.Bar();

foreach (int x; bar.arr)
assert(x == int.init);	// not initialized, fails
}
</code>

tetsuya
Oct 29 2004
parent reply "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
added to dstress as
svn://svn.kuehne.cn/dstress/run/array_initialization_03.d .

It should work, and in fact does so on Linux.
Either this is a Windows spezific problem or you code snipplet is incomplete.

Thomas

tetsuya schrieb:
 dmd 1.04, winXP

 looks like the initialization of an array in a class
 in a template is missing...

 try this code.

 <code>
 template Foo(T, int L)
 {
 T[L] arr;
 class Bar { T[L] arr; }
 }

 unittest
 {
 alias Foo!(int, 100) foo;

 foreach (int x; foo.arr)
 assert(x == int.init); // initialized, no problem

 foo.Bar bar = new foo.Bar();

 foreach (int x; bar.arr)
 assert(x == int.init); // not initialized, fails
 }
 </code>

 tetsuya
Oct 31 2004
parent tetsuya <tetsuya_member pathlink.com> writes:
then it must be a windows specific problem, anyway..
thanks for the report

In article <cm3l21$1peu$4 digitaldaemon.com>, Thomas Kuehne says...
added to dstress as
svn://svn.kuehne.cn/dstress/run/array_initialization_03.d .

It should work, and in fact does so on Linux.
Either this is a Windows spezific problem or you code snipplet is incomplete.

Thomas

tetsuya schrieb:
 dmd 1.04, winXP

 looks like the initialization of an array in a class
 in a template is missing...

 try this code.

 <code>
 template Foo(T, int L)
 {
 T[L] arr;
 class Bar { T[L] arr; }
 }

 unittest
 {
 alias Foo!(int, 100) foo;

 foreach (int x; foo.arr)
 assert(x == int.init); // initialized, no problem

 foo.Bar bar = new foo.Bar();

 foreach (int x; bar.arr)
 assert(x == int.init); // not initialized, fails
 }
 </code>

 tetsuya
Nov 01 2004