static assert(0) in template is a disaster
Paul Backus
snarwin at gmail.com
Tue Jun 16 17:06:33 UTC 2020
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:
>>> On Tuesday, 16 June 2020 at 14:19:06 UTC, Stefan Koch wrote:
>>>> On Tuesday, 16 June 2020 at 14:05:28 UTC, Nils Lankila wrote:
>>>>> Today I've decided to test the new -vtemplates feature.
>>>>> I don't know if what i've found is already known but it
>>>>> looks like a dormant disaster in phobos.
>>>>>
>>>>> [...]
>>>>
>>>> Are you sure it's not the T.stringof ?
>>>
>>> yes. I've removed it after changing the else statement.
>>
>> 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));
More information about the Digitalmars-d
mailing list