[Issue 23973] New: static constructors should have to be nothrow

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 5 16:37:53 UTC 2023


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

          Issue ID: 23973
           Summary: static constructors should have to be nothrow
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: atila.neves at gmail.com

Since initialisation order is undefined, throwing in a static constructor can
end up not having a stack trace (the runtime isn't initialised yet), or
probably worse (the GC insn't initialised yet). Also, there's nothing a user
can actually do to recover since it happens before their program even
technically begins. Even logging the exception is a bad idea because, again,
initialisation (or the lack thereof).

I've been bitten by this and have made all my static constructors nothrow ever
since, and I don't think there's any utility in ones that do.

--


More information about the Digitalmars-d-bugs mailing list