Proposal: Treat static assert in template as instantiation error
Don Clugston
dac at nospam.com.au
Tue Aug 29 09:53:37 PDT 2006
BCS wrote:
> Don Clugston wrote:
>> Kirk McDonald wrote:
>>
>>> Currently, in dmd, if there is an error instantiating a template, the
>>> compiler will quite helpfully print out a traceback to the original
>>> point of instantiation:
>>> It is then pretty clear what the problem is. (You can't pass a char[] to
>>
>> [snip]
>>
>>> By throwing a static assert, the compiler aborts compilation
>>> immediately, and the traceback information is lost. It is no longer
>>> obvious where the template was originally instantiated from.
>>
>>
>> I was also going to post on the same issue. The 'sudden death' static
>> assert was my idea, but we still need to know how it was triggered.
>> One problem with a naive traceback is that if you're not careful, you
>> get the same kind of verbal diarrhea that C++ suffers from (and those
>> error messages really are excrement). In particular, once a static
>> assert has failed, *all* that should be printed is the traceback, not
>> any new error messages.
>>
>> As a minimum, a failed static assert should print the file and line
>> number that the outermost template was originally instantiated from;
>> that would probably be adequate for users of template libraries. A
>> proper traceback would be even better, except for recursive template
>> instantiations. But I think that it's important that once an assert
>> has failed, no new errors should be generated ('error instantiating'
>> is OK, but nothing else), and the compiler should not attempt to
>> compile any further templates.
>>
>
> What about
>
> template foo(int i)
> { // v---
> static assert(i>0, "value "~itoa!(i) ~" !> 0");
> }
I believe that is evaluated before the static assert triggers.
More information about the Digitalmars-d
mailing list