[Issue 19268] BetterC turns off DRuntime for CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 26 23:05:47 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=19268

--- Comment #9 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Adam D. Ruppe from comment #8)
> My view is that the code compiles just fine. Just without druntime linked in
> or generated typeinfo, or whatever it depends on at run time, it will not
> link.
> 
> The -betterC switch tries to detect these these would-be linker errors and
> report them ahead of time, in the compile step, for more consistent and
> user-friendly errors.

Right, this is my view too.

> Since an `if(__ctfe)` branch (or `mixin` or `pragma(msg)` or any other
> unambiguously* compile-time only area) is never actually involved in code
> generation, that linker error will never actually happen... and the compiler
> *should* know that and not cause the ahead-of-time compile error eiter.

Except this is not the problem. The CTFE part DOES compile. It's the part
that's outside that doesn't (in fact typeid(x) does not compile during CTFE).
So how do you "compile" that, and only allow it to run at compile time? That's
why this is hard.

Any solution for detecting druntime usage is not going to be perfect. For
example, this doesn't have compile errors but linker errors (with -betterC):

import core.thread;
import core.time;

extern(C) void main()
{
    Thread.sleep(1.seconds);
}

And of course, __traits(compiles) is going to say YES to this. So it is indeed
a gray area.

--


More information about the Digitalmars-d-bugs mailing list