digitalmars.D.bugs - [Issue 23154] New: Linker error through templated __traits(compiles)
- d-bugmail puremagic.com (71/73) Jun 01 2022 https://issues.dlang.org/show_bug.cgi?id=23154
https://issues.dlang.org/show_bug.cgi?id=23154 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, { T.init.foobar(); }); 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; else alias ResolveThis = SelfRef!T[]; } struct SelfRef(T) { ResolveThis!T payload; size_t foobar() { static if (__traits(compiles, barfoo(payload))) barfoo(payload); return 0; } } alias SelfRefArray = SelfRef!bool; --- foo.d import protocol; unittest { 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__T7SelfRefTbZQl6foobarMFNaNbNiNfZmcollect2: 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. --referenced by __main.d lib.o:(_D8protocol__T6barfooTSQv__T7SelfRefTbZQlZQBcFNaNbNiNfQBgZm)
Jun 01 2022