[Issue 19268] BetterC turns off DRuntime for CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 26 23:08:55 UTC 2020


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

--- Comment #10 from Steven Schveighoffer <schveiguy at yahoo.com> ---
Ooooh, I just had an idea. Consider the template that is causing issues _dup.
What if we did this:

version(D_BetterC) extern(C) void _dup_UNAVAILABLE_IN_BETTERC();

private U[] _dup(T, U)(T[] a) // pure nothrow depends on postblit
{
    if (__ctfe)
    { /* ctfe code */ }

    version(D_BetterC) {
        _dup_UNAVAILABLE_IN_BETTERC();
        return U[].init;
    }
    else:

    // normal implementation that uses typeid
}

This defers the error to the linker, but with the message identifying which
function is causing the problem. We can probably make an easy mixin to do this
wherever needed.

In essence this is a compiler error, with a "funky" but albeit legible message.

But this does change idup to return true for __traits(compiles). Is that a
problem? I'd say no. Use the version(D_BetterC) instead of __traits(compiles).

Aaand, it doesn't work. Using a template at compile time for some reason makes
the compiler want to link in the symbol. I think there is no way to make this
work unless the compiler is smarter about what it used at compile time vs.
runtime.

--


More information about the Digitalmars-d-bugs mailing list