Proposal: static template(fail)

Jason House jason.james.house at gmail.com
Thu Dec 13 08:20:00 PST 2007


Janice Caron Wrote:

> On 12/13/07, Aziz K. <aziz.kerim at gmail.com> wrote:
> > Why not use a static assert: static assert(0, "Substitution Failure");
> 
> A static assert is a compile error. Different thing. What you want is
> for the template not to be instanted, not for it to be instantiated
> with a compile error.
> 
> Put it another way. Suppose you write
> 
>     S(int) s;
> 
> Which would you prefer - an error message saying that s couldn't be
> instantiated (giving the filename and line number of the above line),
> or an error message saying that a static assert in the middle of some
> library file had been hit?

I'd prefer a static assert.
As with all errors, I'd want a backtrace.

Functions currently have in/body/out sections.  I wouldn't mind seeing something like an "in" function for templated objects.  To me, that's much more generic.  In a world without backtraces for errors, it'd also allow a hint to the compiler that it should point the finger at the code that caused the instantiation.



More information about the Digitalmars-d mailing list