www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - two template bugs

reply "Ilya Zaitseff" <sark7 mail333.com> writes:
DMD 0.130

1) This error appears only if X is a template class.

static class X()
{
   static int a;
   static int b = a; // error here
}

void main() {
   X!() x;
}

gives:

bug1.d(4): non-constant expression a

2) This error appears only if Y is a template class and Y inherits from X.

static class X
{
   static class Y(): X
   {
     static class Z
     {
       Y.Z z; // error here
     }
   }
}

void main() {
   X.Y!().Z x;
}

gives:

bug2.d(7): identifier 'Z' of 'Y.Z' is not defined
bug2.d(7): Y.Z is used as a type
bug2.d(7): variable x.X.Y!().Y.Z.z voids have no value
bug2.d(13): template instance x.X.Y!() error instantiating


Maybe I dont understand something important in D templates?
Sep 07 2005
parent reply tetsuya <tetsuya_member pathlink.com> writes:
In article <op.swrd5aogaaezs2 ilya.tec.amursk.ru>, Ilya Zaitseff says...
 <snip>

2) This error appears only if Y is a template class and Y inherits from X.

static class X
{
   static class Y(): X
   {
     static class Z
     {
       Y.Z z; // error here
     }
   }
}

void main() {
   X.Y!().Z x;
}

gives:

bug2.d(7): identifier 'Z' of 'Y.Z' is not defined
bug2.d(7): Y.Z is used as a type
bug2.d(7): variable x.X.Y!().Y.Z.z voids have no value
bug2.d(13): template instance x.X.Y!() error instantiating


Maybe I dont understand something important in D templates?
static class X { static class Y(): X { static class Z { Y!().Z z; } } } void main() { X.Y!().Z x; } will do the job :)
Sep 08 2005
parent tetsuya <tetsuya_member pathlink.com> writes:
In article <op.swrd5aogaaezs2 ilya.tec.amursk.ru>, Ilya Zaitseff says...
DMD 0.130

1) This error appears only if X is a template class.

static class X()
{
   static int a;
   static int b = a; // error here
}

void main() {
   X!() x;
}

gives:

bug1.d(4): non-constant expression a
And for the first one, you have to use static this to evaluate a "variable". static class X() { static int a; static int b; static this() { b = a; } } cheers,
Sep 08 2005