[Issue 20631] New: Calling exit in module destructor yields undefined behaviour

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 3 18:12:45 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20631

          Issue ID: 20631
           Summary: Calling exit in module destructor yields undefined
                    behaviour
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: moonlightsentinel at disroot.org

The following snippet yields inconsistent behaviour depending on the current
platform:

-------------------------------------------
import core.stc.stdlib : exit;
import core.stdc.stdio : printf;

struct X()
{
  static ~this()
  {
     printf("~this()\n");
     fflush(stdout);
     exit(0);
  }
}

static ~this()
{
     printf("g: ~this()\n");
     fflush(stdout);
}

int main() { alias X!() x; return 1; }
-------------------------------------------

Win64:
--------------
~this()
--------------
Exit status 0

Some posix platforms:
--------------
~this()
g: ~this()
--------------
Exit status 0 (???)


(Extracted from runnable/test52.d in DMDs test suite)

--


More information about the Digitalmars-d-bugs mailing list