www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19807] New: undefined reference involving separate

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

          Issue ID: 19807
           Summary: undefined reference involving separate compilation,
                    `unittest`, `double`
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: link-failure
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

eventcore_core.d:
----
struct Tuple()
{
    double expand; /* Floating-point type seems to be significant. */
}

class PosixEventDriver()
{
    unittest
    {
        Tuple!()[] tupList = [];
    }
}

PosixEventDriver!() eventDriver;
----

main.d:
----
import eventcore_core;
void main() {}
----

Compile and (try to) link:
----
dmd -c eventcore_core.d
dmd -c -unittest main.d
dmd main.o eventcore_core.o
----

Output:
----
/usr/bin/ld:
main.o:(.data._D38TypeInfo_S14eventcore_core__T5TupleZQh6__initZ+0x28):
undefined reference to `_D14eventcore_core__T5TupleZQh6__initZ'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
----

Linking should succeed.

Encountered during Phobos development:
https://github.com/dlang/phobos/pull/6951#issuecomment-482470928

--
Apr 14 2019