static assert(0) in template is a disaster

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Jun 17 12:46:00 UTC 2020


On 6/17/20 3:05 AM, Timon Gehr wrote:
> 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;

Yah that's what I had in mind. Problem is made worse if the definitions 
are in different modules.

>> 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.)

I guess that's what you get when one proceeds with too little formalism.


More information about the Digitalmars-d mailing list