Feature Request: Location of template instantiation failure
Bill Baxter
dnewsgroup at billbaxter.com
Tue Dec 11 11:20:58 PST 2007
Janice Caron wrote:
> Consider the following code
>
> import std.stdio;
>
> int f(int N)(int x)
> {
> static assert(N >= 0 && N < 10); // line 5
> return N + x;
> }
>
> void main()
> {
> writefln(f!(3)(3));
> writefln(f!(13)(1)); // line 12
> writefln(f!(7)(2));
> }
>
> It won't compile. This is correct. I don't want it to compile.
>
> What concerns me is that there's no way to locate the real error. The
> error message which the compiler emits is:
>
> test.d(5): static assert is false
>
> There is indeed a static assert on line 5, and for ONE of the
> instantiations it comes out false. But the /real/ error is on line 12,
> where I pass an invalid parameter to the template. The compiler
> doesn't tell me that.
>
> So ... feature request: If the DMD compiler is unable to instantiate a
> template, then, as part of the error reporting, please could it print
> out the filename and line number of the line which triggered the
> instantiation? It would be so much more helpful to see:
>
> test.d(5): static assert is false
> test.d(12): instantiation failure
>
> or similar.
Amen to that. We need template instantiation stack traces. Thanks to
Jascha and ddbg we can now get the run-time stack traces easily, but
we're still up a creek with nothing but a couple of toothpicks when it
comes to tracking down the source of compile-time template errors.
--bb
More information about the Digitalmars-d
mailing list