D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10851 - Stack trace missing for null object access in module constructor
Summary: Stack trace missing for null object access in module constructor
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-19 03:09 UTC by Andrej Mitrovic
Modified: 2024-12-13 18:10 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-08-19 03:09:24 UTC
-----
shared static this()
{
    class C
    {
        void foo() { }
    }

    C c;
    c.foo();
}

void main()
{
}
-----

$ dmd -g -run test.d
> object.Error: Access Violation

When using the same code in main, a proper stack trace is returned:

-----
module test;

void main()
{
    class C
    {
        void foo() { }
    }

    C c;
    c.foo();
}
-----

object.Error: Access Violation
----------------
0x0040201B in _Dmain at C:\dev\code\d_code\stack_trace_working.d(11)
0x004028E4 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).v
oid runMain()
0x00402974 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).v
oid runAll()
0x00402251 in _d_run_main
0x00402074 in main
0x004141AD in mainCRTStartup
0x766C33CA in BaseThreadInitThunk
0x77C19ED2 in RtlInitializeExceptionChain
0x77C19EA5 in RtlInitializeExceptionChain

Tested on Win 7 64bit.
Comment 1 kekeniro2 2013-10-25 21:11:54 UTC
I hit this.

Written in core.runtime.d :
static this()
{
    // NOTE: Some module ctors will run before this handler is set, so it's
    //       still possible the app could exit without a stack trace.  If
    //       this becomes an issue, the handler could be set in C main
    //       before the module ctors are run.
    Runtime.traceHandler = &defaultTraceHandler;
}

At least, it had better be changed to 'shared static this'.
Comment 2 dlangBugzillaToGithub 2024-12-13 18:10:34 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18652

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB