[Issue 2816] Sudden-death static assert is not very useful

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 9 02:24:27 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2816





------- Comment #9 from clugdbug at yahoo.com.au  2009-04-09 04:24 -------
Error messages generated from my patch for the code below:
bug.d(2): Error: static assert  (0) is false
bug.d(9):        instantiatied from here: bar!()
bug.d(14):        100 recursive instantiations from here: foo!(196)
bug.d(19):        253 recursive instantiations from here: baz!(300)

(Oops -- just realised I there's a typo in "instantiated" in the non-recursive
messages. That's easy to fix).
Note that it detects the recursive instantiation in foo!(), even though it is
instantiated from three different places.

--------
template bar() {
   static assert(0);
}

template foo(int N) {
  static if (N>0) {
     static if (N&1) alias foo!(N-3) foo;
     else alias foo!(N-1) foo;
  } else alias bar!() foo; 
}

template baz(int M) {
   static if (M<50) {
     alias foo!(M*4) baz;
   } else alias baz!(M-1) baz;
}

void main() {
  int x = baz!(300);
}


-- 



More information about the Digitalmars-d-bugs mailing list