Mixin templates vs interface files
Jean-Louis Leroy via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 6 06:24:23 PDT 2017
Consider:
// app.d
import std.stdio;
import tracemodule;
mixin traceModule;
void main()
{
writeln("main");
}
// tracemodule.d
module tracemodule;
import std.stdio;
mixin template traceModule(string moduleName = __MODULE__)
{
import std.stdio;
static this()
{
writeln("init " ~ moduleName);
}
static ~this()
{
writeln("deinit " ~ moduleName);
}
}
When I compile like this:
$ rm -f *.o *.di
$ dmd -c tracemodule.d
$ dmd -c app.d
$ dmd app.o tracemodule.o -of=app
...and run 'app' I get the expected output:
$ ./app
init app
main
deinit app
Now if I throw -H in, things get weird:
$ rm -f *.o *.di
$ dmd -c -H tracemodule.d
$ dmd -c app.d
$ dmd app.o tracemodule.o -of=app
$ ./app
init app
main
Indeed when I look at the content of the interface file, I see:
// D import file generated from 'tracemodule.d'
module tracemodule;
import std.stdio;
template traceModule(string moduleName = __MODULE__)
{
import std.stdio;
static this()
{
writeln("init " ~ moduleName);
}
}
'static this()' is there, but no 'static ~this()'.
What's happening here?
More information about the Digitalmars-d
mailing list