Christian Kamm wrote:
Max Samukha wrote:
static assert should at least print the location of the instantiating
code or better the entire backtrace. This has been asked for several
times.

Jarrett Billingsley Wrote:
The code to do this is already in the frontend, DMD and it used to do
it.  It's just been disabled.  LDC already prints template
instantiation traces.

Yes, it wasn't hard to output a template instantiation trace when a static 
assert is hit. LDC produces errors like this:

templatecode.d(9): Error: static assert  "first arg must be numeric"
    instantiatied in templatecode.d(4): impldetail!(void,void[],int)
    instantiatied in myhugefile.d(4109): uservisible!(void)

Support for these traces is not exhaustive - there is none for fatal errors, 
for instance - but since it's guaranteed to work for static asserts it is 
already very useful if the library author detected the error.

I emailed Walter about it at the time, but either he missed it or is still of 
the opinion that instantiation traces are too verbose and confuse the 
programmer. While I agree that they aren't ideal, they are still a huge time 
saver when using and writing template libraries and should be enabled until D 
introduces a better way to do template error handling.

In order to avoid showing too much implementation details in the error message, 
the compiler could make an educated guess about what part of the instantiation 
chain is of interest to the user. For instance, template instantiations in 
imported modules could be skipped (if they're private?). I didn't think about 
that when I added the traces, so LDC currently just prints up to six steps or 
all if -v is given.

Ideally, it would also detect recursive template instantiations -- only show (say) the first and the last instantiation of templates with the same name. You always want to see the initial template instantiation.

Reply via email to