static assert(0) in template is a disaster

Timon Gehr timon.gehr at gmx.ch
Wed Jun 17 07:05:25 UTC 2020


On 17.06.20 03:26, Andrei Alexandrescu wrote:
> On 6/16/20 7:01 PM, Paul Backus wrote:
>> I agree that this is a bug, but it is a bug in the design of the 
>> language itself, not the implementation.
> 
> Is that a sort of a compile-time race condition?

Not exactly as there is a clear ordering of declarations. Rather, it's a 
self-contradicting program, like this one:

static if(!is(typeof(x))) int x;

This would be an example of a race condition:

static if(!is(typeof(x))) int y;
static if(!is(typeof(y))) int x;

> If that's the case, D 
> should deem the program ill-formed with no diagnostic required.

Unfortunately, if dependency structures get a bit tricky, DMD will fail 
to correctly compile even well-formed programs. It's why I have 
refrained from going too crazy with metaprogramming after my experience 
with my D frontend that stopped compiling after DMD 2.060. (Ironically, 
it does produce a diagnostic for each of the examples discussed here.)


More information about the Digitalmars-d mailing list