Feature Request: Location of template instantiation failure

Janice Caron caron800 at googlemail.com
Tue Dec 11 07:05:30 PST 2007


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.



More information about the Digitalmars-d mailing list