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
Comment #1 by kinke — 2019-04-14T12:28:13Z
The `double` field is required to make the Tuple struct template non-zero-initialized, so that the init symbol is actually required. You'd have the same issue with an `int expand = 1` field.
For some reason, the TypeInfo for Tuple is emitted into the `main` module, but the init symbol isn't.
Comment #2 by kinke — 2019-04-14T12:40:04Z
Another question is whether the unittest is actually supposed to be 'instantiated' by the import of the module alone. The PosixEventDriver class template isn't instantiated in the main module, so I'd say it should not.
Comment #3 by ag0aep6g — 2019-04-14T22:19:35Z
A slight variation with opEquals and opCmp:
----
struct Tuple()
{
bool opEquals(const Tuple other) const { assert(false); }
int opCmp(const Tuple other) const { assert(false); }
}
----
Rest as above.
Output:
----
/usr/bin/ld: main.o: in function `_D14eventcore_core__T5TupleZQh11__xopEqualsFKxSQBt__TQBgZQBkKxQqZb':
main.d:(.text._D14eventcore_core__T5TupleZQh11__xopEqualsFKxSQBt__TQBgZQBkKxQqZb[_D14eventcore_core__T5TupleZQh11__xopEqualsFKxSQBt__TQBgZQBkKxQqZb]+0xe): undefined reference to `_D14eventcore_core__T5TupleZQh8opEqualsMxFNaNbNiNfxSQBy__TQBlZQBpZb'
/usr/bin/ld: main.o: in function `_D14eventcore_core__T5TupleZQh8__xopCmpFKxSQBp__TQBcZQBgKxQqZi':
main.d:(.text._D14eventcore_core__T5TupleZQh8__xopCmpFKxSQBp__TQBcZQBgKxQqZi[_D14eventcore_core__T5TupleZQh8__xopCmpFKxSQBp__TQBcZQBgKxQqZi]+0xb): undefined reference to `_D14eventcore_core__T5TupleZQh5opCmpMxFNaNbNiNfxSQBv__TQBiZQBmZi'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
----
Comment #4 by robert.schadek — 2024-12-13T19:03:01Z