static assert(0) in template is a disaster

Nils Lankila NilsLankila at gmx.us
Tue Jun 16 18:14:26 UTC 2020


On Tuesday, 16 June 2020 at 17:06:33 UTC, Paul Backus wrote:
> On Tuesday, 16 June 2020 at 16:57:50 UTC, Nils Lankila wrote:
>> On Tuesday, 16 June 2020 at 14:26:18 UTC, Stefan Koch wrote:
>>> On Tuesday, 16 June 2020 at 14:22:25 UTC, Nils Lankila wrote:
>>>> [...]
>>>
>>> Thank you very much for finding this.
>>>
>>> I'll be having a look at this shortly.
>>
>> The problem is quite clear.
>>
>> If a template fails once to instantiate with a given set of 
>> template parameters then it will always fail with the same set 
>> of parameters.
>
> Unfortunately this is not true:
>
> template example(T)
> {
>     static assert(__traits(hasMember, T, "x"));
>     alias example = T.x;
> }
>
> struct S
> {
>     static if (!__traits(compiles, example!S)) {
>         int x;
>     }
> }
>
> static assert(is(typeof(example!S) == int));

that's unfortunate, looks like the problem cant be solved then.


More information about the Digitalmars-d mailing list