Bug 6631 – core.time module constructor runs AFTER main program's module constructor
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-09-08T17:30:00Z
Last change time
2012-04-27T14:42:25Z
Assigned to
nobody
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2011-09-08T17:30:31Z
(This might be a DMD bug)
import core.time;
static this()
{
assert(TickDuration.ticksPerSec != 0);
}
void main() {}
The above will fail, because the core.time module constructor will not have ran when the check is performed. The assert will pass if moved inside main().
Comment #1 by schveiguy — 2011-09-09T04:33:45Z
This is truly a bug somewhere, because your static ctor is not shared, yet the static ctor that sets ticspersec is shared. Shared static ctors should be run *before* non-shared ones, so this has nothing to do with dependencies.
Examining the generated assembly, it's identical whether you include it in main or static this, and it does access the actual member, not some optimized-out constant.
So I think it *must* be running the shared ctor *after* the unshared one. This is likely not a problem with druntime, but rather the compiler. I'll try to investigate further to see why the module is run later. Perhaps the @trusted is giving dmd fits on the shared ctor. But even so, core.time should be a dependency of the main program module, so it should still be run first.
Comment #2 by dlang-bugzilla — 2011-09-09T05:27:48Z
Note that adding "shared" to the main module constructor doesn't change the situation.
Comment #3 by schveiguy — 2011-09-09T08:05:25Z
Right, what I was saying though is that all shared ctors are run before all non-shared ones. So it is very surprising that a shared ctor has *not* been run before a non-shared one, regardless of dependency.
Comment #4 by lovelydear — 2012-04-27T14:37:45Z
Compiles and runs with 2.059 Win32
Comment #5 by dlang-bugzilla — 2012-04-27T14:42:25Z