Thread overview
two template bugs
Sep 08, 2005
Ilya Zaitseff
Sep 09, 2005
tetsuya
Sep 09, 2005
tetsuya
September 08, 2005
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?
September 09, 2005
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 :)


September 09, 2005
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,