www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23154] New: Linker error through templated __traits(compiles)


          Issue ID: 23154
           Summary: Linker error through templated __traits(compiles) in
                    separate compilation unit
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: d.bugs webfreak.org

minimized reproduction test case:
--- protocol.d
enum hasCallableFoobar(T) = __traits(compiles,

size_t barfoo(T)(T )
if (is(T == S[], S) && hasCallableFoobar!S)
    return 0;

size_t barfoo(T)(T val)
    static if (hasCallableFoobar!T)
        return val.foobar;

template ResolveThis(T)
    static if (is(T : SelfRef!U, U))
        alias ResolveThis = T;
        alias ResolveThis = SelfRef!T[];

struct SelfRef(T)
    ResolveThis!T payload;

    size_t foobar()
        static if (__traits(compiles, barfoo(payload)))
        return 0;

alias SelfRefArray = SelfRef!bool;

--- foo.d
import protocol;

        SelfRef!(SelfRefArray) x;


to test:

dmd -lib -ofprotocol.a protocol.d
dmd -main -c -oflib.o -unittest -I. foo.d
dmd -oftestlib lib.o protocol.a

observe that there is no compiler error for potential issues, but also we are
failing with a linker error:

ld: error: undefined symbol: _D8protocol__T7SelfRefTbZQl6foobarMFNaNbNiNfZm
 referenced by __main.d
collect2: error: ld returned 1 exit status Error: linker exited with status 1 Note: in my actual code this is much much more complex, basically calling Variant!MyVariant j; j.match!(v => v); with MyVariant being defined as Variant!JsonAlgebraic in another compilation unit. --
Jun 01 2022