www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feature Request: Location of template instantiation failure

reply "Janice Caron" <caron800 googlemail.com> writes:
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.
Dec 11 2007
next sibling parent Oskar Linde <oskar.lindeREM OVEgmail.com> writes:
Janice Caron wrote:

 
 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

DMD used to do this, which often resulted in error messages of 1000 of lines. It would still be very useful to get the old behavior back via a compiler switch though. -- Oskar
Dec 11 2007
prev sibling next sibling parent bearophile <bearophileHUGS lycos.com> writes:
In one situation I have "solved" this problem giving the template the __LINE__
too. But it's not nice. In C you can solve this problem using macros:
http://users.bestweb.net/~ctips/tip012.html
So I think that idea of yours is nice. If the problem is too many errors, Javac
has a flag to limit the number errors it shows.

Bye,
bearophile
Dec 11 2007
prev sibling next sibling parent reply BCS <BCS pathlink.com> writes:
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.

how about a template stack trace? test.d(5): static assert is false test.d(12): f instantiation failure bob.d(21): foo instantiation failure . . .
Dec 11 2007
parent BCS <BCS pathlink.com> writes:
BCS wrote:

 
 how about a template stack trace?
 
 test.d(5): static assert  is false
 test.d(12): f instantiation failure
 bob.d(21): foo instantiation failure
 .
 .
 .
 
 

now that I have looked at Oskar's post: trim out all but the some amount of the head and tail of the above (and add the args into the listing)
Dec 11 2007
prev sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
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
Dec 11 2007