--- test1.d
mixin template C(bool isBase)
{
this(int x)
{
static if (!isBase)
{
super(x);
}
}
}
class B
{
public:
mixin C!true;
}
--- test2.d
import test1;
mixin template C2(bool isBase)
{
this(int x, string y)
{
static if (isBase)
{
super(x);
}
else
{
super(x, y);
}
}
}
class E : B
{
public:
mixin C!false;
mixin C2!true;
}
--- test3.d
import test1;
import test2;
void main()
{
auto b = new B(0);
auto e = new E(0, "");
}
Error as below from online compiler - https://run.dlang.io/?compiler=dmd
If merge test2 to test1, no error taken place
/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o:function _start:(.text+0x1b): error: undefined reference to 'main'
test2.o:/sandbox/test2.d:_D5test21E7__ClassZ:(.data._D5test21E7__ClassZ+0x50): error: undefined reference to '_D5test11B7__ClassZ'
./test1.d:7: error: undefined reference to '_D5test11B8__mixin16__ctorMFiZCQBdQBa'
/sandbox/test2.d:9: error: undefined reference to '_D5test11B8__mixin16__ctorMFiZCQBdQBa'
collect2: error: ld returned 1 exit status
Error: undefined reference to `main`
referenced from `_start`
Error: undefined reference to `test1.B.__Class`
Error: undefined reference to `test1.B test1.B.__mixin1.__ctor(int)`
Error: undefined reference to `test1.B test1.B.__mixin1.__ctor(int)`
perhaps define a `void main() {}` function or use the `-main` switch
Error: linker exited with status 1
cc test2.o -o test2 -g -m64 -Xlinker --export-dynamic -L/dlang/dmd/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl
--- test1.d
--- test2.d
--- test3.d
Error as below from online compiler - https://run.dlang.io/?compiler=dmd
If merge test2 to test1, no error taken place