www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Request: When static assert fails, display original instantiation

reply Don Clugston <dac nospam.com.au> writes:
Using the "sudden-death" static asserts, template libraries can now 
generate very high-quality error messages (in contrast to the garbage 
you usually get in C++). There's a problem, though: "sudden-death" 
static asserts is that they only tell you the line where the static 
assert is, but they normally refer to a problem where the template was 
instantiated from.
So we get error messages like:

library.d(375): (num<50), Number is too big

This has been adequate for library developers, but is unusable for 
library users. We don't need a full template trace, just the original 
file and line where the first template instantiation or mixin was done 
from. Something like:

myproject.d(20): caused static assert in:
library.d(375): (num<50) is false, Number is too big

Or:...

library.d(375): (num<50) is false, Number is too big
myproject.d(20): ultimately instantiated from here.

Coupled with Oskar's recent request for a flag to re-enable template 
backtrace (maybe -nogag or -backtrace) for library developers, I think 
this would completely solve the template error message problem.
Nov 22 2006
parent Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Don Clugston wrote:
 Using the "sudden-death" static asserts, template libraries can now 
 generate very high-quality error messages (in contrast to the garbage 
 you usually get in C++). There's a problem, though: "sudden-death" 
 static asserts is that they only tell you the line where the static 
 assert is, but they normally refer to a problem where the template was 
 instantiated from.
 So we get error messages like:
 
 library.d(375): (num<50), Number is too big
 
 This has been adequate for library developers, but is unusable for 
 library users. We don't need a full template trace, just the original 
 file and line where the first template instantiation or mixin was done 
 from. Something like:
 
 myproject.d(20): caused static assert in:
 library.d(375): (num<50) is false, Number is too big
 
 Or:...
 
 library.d(375): (num<50) is false, Number is too big
 myproject.d(20): ultimately instantiated from here.
 
 Coupled with Oskar's recent request for a flag to re-enable template 
 backtrace (maybe -nogag or -backtrace) for library developers, I think 
 this would completely solve the template error message problem.
We've discussed this before, of course, and it's annoying enough that I'm glad you've brought it up again. Here's an earlier thread on this topic: "Proposal: Treat static assert in template as instantiation error" http://www.digitalmars.com/d/archives/digitalmars/D/41749.html -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Nov 23 2006