Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

Change Log: 2.113.0

previous version: 2.112.0

Download D 2.113.0 Beta
to be released Aug 05, 2026

2.113.0 comes with 16 major changes and 0 fixed Bugzilla issues. A huge thanks goes to the 236 contributors who made 2.113.0 possible.

List of all bug fixes and enhancements in D 2.113.0.

Compiler changes

  1. Support for default values in C-style bitfields

    D now supports specifying default values for C-style bitfields in structs and classes. This brings valid D code closer to behavior allowed in C++20 and allows for more concise initialization of bitfield members.

    Value range checking is performed at compile-time to ensure the default value fits within the specified number of bits.

    struct S
    {
        int a : 4 = 2;   // OK
        int b : 2 = 5;   // Error: bitfield initializer `5` does not fit in 2 bits
        uint c : 1 = 1;  // OK
        bool d : 1 = 1;  // OK
    }
    
  2. Destructors now run in a nothrow function when an Error unwinds through it

    Destructors and scope(exit) blocks internally generate try-finally statements. Since 2018, DMD has optimized finally blocks in nothrow try bodies by rewriting them into a simple sequence, avoiding the overhead of exception unwinding. However, this optimization also skipped finally blocks when an Error was thrown, preventing expected cleanup from running.

    This optimization has been reverted to the pre-2018 behavior: finally blocks always run, regardless of whether the try body can throw an Exception.

    To reenable the optimization, use the new -nothrow-optimizations switch.

    The following example demonstrates the fix - "exiting!" is now printed even though callMe is a nothrow function:

    import core.stdc.stdio;
    
    void main()
    {
        S s2;
        callMe();
    }
    
    struct S
    {
        ~this()
        {
            printf("exiting\n");
        }
    }
    
    void callMe() nothrow
    {
        throw new Error("hi there :)");
    }
    

    The -betterC switch is unaffected by this change.

  3. New experimental Data Flow Analysis Engine for nullability and truthiness

    A new experimental Data Flow Analysis (DFA) has been implemented under the preview flag -preview=fastdfa. The intent of the engine is to be both fast and free from false positives, if successful it may in the future be turned on by default.

    No attributes have been implemented to date, before they are considered the engine itself must be both usable with the right tradeoffs and have desirable features. This has some side effects, it prevent separate compilation, function pointers, and cyclic functions from being analysable. These limitations are not supposed to prevent a successful compilation when in use.

    The engine itself is variable centric with a strong focus on giving up on analysing a variable if things get too complex for it. This can result in messages that may not appear to make sense for where they are emitted, due to the way shortcutting of analysis works. As an example of loops:

    void loopy()
    {
        int* ptr = new int;
    
        foreach (i; 0 .. 2) // Error: Variable `ptr` was required to be non-null and has become null
        {
            int val = *ptr;
            ptr = null;
        }
    }
    

    If the engine is successful, the reporting mechanism would be replaced with a tracing state pass. This would offer for a function line by line explanation of how and why the engine thought something was true.

    The engine has been tested on a 100k LOC defensively written codebase without any false positives. The performance is similar to DIP1000 and is not supposed to be noticeable.

  4. Fast DFA reports on uninitialized variable reads

    The fast DFA engine has gained the ability to error when a variable can be proven to being in an uninitialized state, and is read.

    void readFromUninit() @system
    {
        int val1 = void;
        int val2 = val1; // error
    
        int* ptr = &val1;
        int val3 = *ptr; // error
    }
    

    As part of this it is now capable of looking through pointers and seeing properties of variables that are on the stack.

    An application of this feature is the prevention of mathematical operators from accessing default initialized floating point types.

    void checkFloatInit(bool condition)
    {
        float v;
        float t = v * 2; // error math op
    
        if (condition)
            v = 2;
    
        float u = v * 2; // no error
    }
    

    It will not activate for other expressions, or statements. Only in a mathematical expression.

    This was not originally part of the fast DFA engines scope, its continued existence depends upon community feedback as part of usage.

  5. Improve -ftime-trace template instance detail

    The -ftime-trace profiling output now includes template argument types in the event name for template instance events, allowing users to distinguish between different instantiations of the same template (e.g. isArray!(int) instead of just isArray).

  6. Added __traits(needsDestruction, T)

    True if T is a value type needing elaborate destruction. This includes structs with explicit ~this() destructors and/or compiler-generated destructors (caused by fields needing destruction), static arrays thereof, and enums with such base types.

    class C { ~this(); }
    struct S { ~this(); }
    
    static assert(!__traits(needsDestruction, C));
    static assert(__traits(needsDestruction, S));
    static assert(!__traits(needsDestruction, S[0]));
    static assert(__traits(needsDestruction, S[1]));
    
  7. New trait __traits(isOverlapped, field) to detect overlapping fields

    D now provides a compile-time trait to check whether a struct or class field overlaps with other fields in memory. This is useful for serialization libraries, code generators, and metaprogramming tasks that need to identify fields sharing the same memory location.

    The trait takes a single field argument, returning true if the field's storage overlaps with other fields (typically because it is part of a union).

    struct S
    {
        int a;
        union
        {
            int x;  // overlaps with y
            float y;  // overlaps with x
        }
        int b;
    }
    
    static assert(__traits(isOverlapped, S.x));  // true
    static assert(__traits(isOverlapped, S.y));  // true
    static assert(!__traits(isOverlapped, S.a)); // false - regular field
    static assert(!__traits(isOverlapped, S.b)); // false - regular field
    

    The trait works with both anonymous and named unions:

    union NamedUnion
    {
        int x;
        float y;
    }
    
    static assert(__traits(isOverlapped, NamedUnion.x));  // true
    static assert(__traits(isOverlapped, NamedUnion.y));  // true
    

    This trait is particularly useful for:

    • Serialization libraries that need to handle only one field from overlapping sets
    • Understanding memory layout and field interaction
    • Implementing correct destructors for types with overlapping fields
    • Generic code that needs to reason about field storage semantics

    The trait exposes DMD's internal overlap tracking (VarDeclaration.overlapped), providing a direct way to query this semantic property.

  8. An optional check for null dereference is added

    A new check has been implemented that injects code to check a pointer for null before it is dereferenced.

    It will be typically be used if you need a backtrace generated (when one is not automatically done), or if you want to catch and handle the Error as part of a scheduler.

    This can be enabled by using -check=nullderef=on by default it is off. What happens may be customized by the -checkaction switch and by setting a new handler in core.exception.

    Due to issues in dmd's backend, not all pointer dereferences are guaranteed to get a check.

  9. Allow certain pragma(printf) function calls to be treated as @safe

    printf function calls in general are unsafe. Many calls, however, can be automatically checked for safety.

    This change allows calling a pragma(printf) function from @safe code when:

    • the callee is marked @safe or @trusted
    • the format string passed is a literal
    • no zero-terminated string format specifiers are used

    Note: pragma(printf) already enforces type safety.

    For example:

    extern(C) pragma(printf)
    void printf(const char* format, ...) @trusted;
    
    @safe void func(int i, char* s)
    {
        printf("i is %d\n", i);  // allowed
        printf("s is %s\n", s);  // Error: call is not safe
        printf(s);               // Error: call is not safe
    }
    
  10. Add support for static array length inference

    Added support for using $ to automatically infer the length of a static array from its initializer. This allows for cleaner declarations without manually counting elements.

    int[$] arr = [1, 2, 3]; // Length is inferred as 3
    
  11. The compiler now inlines pragma(inline, true) functions in a separate pass

    The compiler now considers pragma(inline, true) functions for inlining in a dedicated pass before trying to inline other eligible functions. This provides better control of inlining decisions, for example:

    auto staticSquares(uint n)()
    {
        int[n] arr;
        static foreach(i; 0 .. n)
            arr[i] = (i + 1) ^^ 2;
        return arr;
    }
    
    pragma(inline, true) int thirtyThirty()
    {
        return staticSquares!30[$ - 1];
    }
    

    Previously, dmd -inline would first inline staticSquares() into thirtyThirty() and subsequently fail to inline thirtyThirty() into its callers. With the new implementation, the programmer can expect the compiler to replace calls to thirtyThirty() with staticSquares!30[$ - 1] before making other inlining decisions.

  12. -vgc now reports locations of nested functions that create closures

    When a GC-allocated closure was created, the -vgc switch would only point to the outer function that a closure was created for. For a big function, this still requires you to search where the nested function requiring the closure actually is. It now reports the closure function and variable location just like in error messages for @nogc.

    auto closure()
    {
        int x;
        int bar() { return x; }
        return &bar;
    }
    

    After:

    vgc.d(1): vgc: using closure causes GC allocation
    

    vgc.d(1): vgc: using closure causes GC allocation
    vgc.d(4): vgc: function bar closes over variable x
    vgc.d(3): vgc: x declared here
    

  13. Add support for with(auto x = expression())

    Added support for using with statements with an expression initialiser as an AssignExpression, like if, while for and switch`. For backwards compatibility, with still also accepts a qualified expression without assignment to a variable as in with(immutable expression()).

Runtime changes

  1. Gravedigger approach to Throwables escaping a thread entry point is now available

    A new method is added to ThreadBase enabling filtering of any Throwable's before it is handled by the thread abstraction. This may be used per-thread and globally, to log that an Error has occured or to exit the process.

    A reasonable error handler that may be of use is:

    import core.exception;
    
    void main()
    {
        filterThreadThrowableHandler = (ref Throwable t) {
            import core.stdc.stdio;
            import core.stdc.stdlib;
    
            if (auto e = cast(Error) t)
            {
                auto msg = e.message();
                fprintf(stderr, "Thread death due to error: %.*s\n", cast(int)msg.length, msg.ptr);
                fflush(stderr);
                abort();
            }
        };
    }
    

    For a per thread handler the following example may be what you want:

    import core.thread;
    
    class MyThread : Thread
    {
        this( void function() fn, size_t sz = 0 ) @safe pure nothrow @nogc
        {
            super(fn, sz);
        }
    
        this( void delegate() dg, size_t sz = 0 ) @safe pure nothrow @nogc
        {
            super(dg, sz);
        }
    
        override void filterCaughtThrowable(ref Throwable t) @system nothrow
        {
            import core.stdc.stdio;
            import core.stdc.stdlib;
    
            if (auto e = cast(Error) t)
            {
                auto msg = e.message();
                fprintf(stderr, "Thread death due to error: %.*s\n", cast(int)msg.length, msg.ptr);
                fflush(stderr);
                abort();
            }
    
            super.filterCaughtThrowable(t);
        }
    }
    

Library changes

  1. variant: Support big structs with @disabled this()

    std.variant didn't compile when the payload was a struct that was bigger than its internal buffer and had to be allocated on the heap if that struct @disabled this(). The new handling now always skips the constructor and just copies the directly to the allocated regions.

Dub changes

  1. Added --timeout option to dub dustmite command.

    Adds a timeout (in seconds) for each oracle invocation, preventing the dustmite process from hanging indefinitely when the test command does not terminate. Requires the timeout command to be available (coreutils on Linux/macOS).


List of all bug fixes and enhancements in D 2.113.0:

DMD Compiler bug fixes

  1. DMD Issue 17224: No way to get notified about D runtime termination.
  2. DMD Issue 17531: Using a custom pow function for ^^
  3. DMD Issue 18337: Coverage always report 0000000 for inlined function
  4. DMD Issue 19499: pragms(lib) and pragma(linkerDirective) can emit duplicate entries to the object
  5. DMD Issue 19675: fatal error LNK1179 on windows-x86_64-dmd with MSVC
  6. DMD Issue 19721: __traits(getMember) should not allow safe code to access private fields
  7. DMD Issue 19829: Appending to keys of an empty associative array "cannot be interpreted at compile time"
  8. DMD Issue 19905: Type list (tuple) not expanded in delegate during IFTI
  9. DMD Issue 20053: Line with spaces in cmdfile is treated as multiple arguments
  10. DMD Issue 20425: ImportC: Assignment to double complex fails when using ternary operator
  11. DMD Issue 20439: "Undefined reference to internal" when -c with SysTime.max in init
  12. DMD Issue 20578: dmd -inline segfault on windows, mac, linux
  13. DMD Issue 20997: Alias template parameter with type specialization rejects valid argument
  14. DMD Issue 21039: Zero-length static array with scalar initializer causes ICE
  15. DMD Issue 21194: Modifying global char[] initialized with dup of string literal causes segfault
  16. DMD Issue 21637: ICE in tuple comparison
  17. DMD Issue 21707: Segfault with -vcg-ast and foreach on a sequence
  18. DMD Issue 21839: ICE - Crash when using void[N].init
  19. DMD Issue 21976: [REG 2.112.0] Array comparison performance regression
  20. DMD Issue 22153: importc: cannot use forward declaration of static function when building a library
  21. DMD Issue 22229: scope should be inferred when assigning a scope variable to another variable
  22. DMD Issue 22282: Applying a UDA to a File-type variable causes DMD to crash
  23. DMD Issue 22363: Noreturn variable access is not always detected
  24. DMD Issue 22381: out-of-bounds access when masking ushort
  25. DMD Issue 22394: Error in lambda should show call line as well as definition line
  26. DMD Issue 22397: DMD 2.112.0 fails to compile an array variable initialization with an array literal and a UDA
  27. DMD Issue 22399: Low-level threading support on Windows DLLs are broken
  28. DMD Issue 22406: [REG 2.112] Error: function '_d_aaLen' is not callable using argument types '(shared(int[int]))'
  29. DMD Issue 22427: Premature removal of ternary of type noreturn
  30. DMD Issue 22430: noreturn evaluation in ConditionalExpression is ignored
  31. DMD Issue 22463: SOURCE_DATE_EPOCH parsing incorrectly affected by system timezone
  32. DMD Issue 22481: Inliner silently removes return in loops
  33. DMD Issue 22489: DMD miscompiles real types in the presence of aliasing
  34. DMD Issue 22504: [REG 2.112] druntime fails to build on powerpc64le-linux-gnu
  35. DMD Issue 22512: [REG 2.112] druntime fails to build on sparcv9-sun-solaris2.11
  36. DMD Issue 22517: [REG 2.106] Allocating an array of type void[] is marked as not containing pointers
  37. DMD Issue 22544: [REG 2.112] Cannot index AA in with block
  38. DMD Issue 22560: [REG master] Can supposedly index AA with mismatching key type
  39. DMD Issue 22594: [REG 2.101] TypeInfo_Class.m_flags wrong wrt. noPointers flag when the only pointers come from tuple members
  40. DMD Issue 22613: Consecutive initialization fails with postblits
  41. DMD Issue 22621: Anonymous struct inside anonymous union not considered overlapped
  42. DMD Issue 22647: dmd as library fails to link with dub test --coverage
  43. DMD Issue 22658: __traits(isCopyable) fails on static array of non-copyable struct
  44. DMD Issue 22659: ICE when assigning to a slice cast to static array type
  45. DMD Issue 22667: ImportC: generating .di turns void into _IO_lock_t
  46. DMD Issue 22711: -ftime-trace: semantic_analysis block is too coarse for useful profiling
  47. DMD Issue 22754: I really want a way to omit __monitor from Object
  48. DMD Issue 22769: ICE on IFTI call inside interpolated string
  49. DMD Issue 22925: [REG 2.113] ICE: AssertError@expression.d(508) with invalid case range statement
  50. DMD Issue 22980: "named arguments not allowed here" in const constructor
  51. DMD Issue 23065: [REG2.112.0] AA-equality fails compilation with self-referential types
  52. DMD Issue 23081: druntime parallel GC livelock: scanBackground spins when evStackFilled left set with empty scan stack
  53. DMD Issue 23133: [Reg 2.109.1] GC.collect() no longer scans in concurrent threads
  54. DMD Issue 23182: [REG 2.112.0] Duplicate __aaget declaration for simple expression with associative array
  55. DMD Issue 23320: Constness and immutability of AA keys is handled unflexibly
  56. DMD Issue 23359: Tuple parameter UDAs not propagated to expanded elements

Phobos bug fixes

  1. Phobos Issue 9783: std.variant doesn't do postblit/dtor correctly for large structs
  2. Phobos Issue 9871: cartesianProduct should have length for finite ranges
  3. Phobos Issue 10062: std.variant does not observe value semantics for large value types.
  4. Phobos Issue 10429: Variant and tuples by index
  5. Phobos Issue 10743: Nullable should implement opCmp
  6. Phobos Issue 10858: Documentation of std.logger: trace() does not work by default
  7. Phobos Issue 10916: std.format reads past end of input
  8. Phobos Issue 10940: Inconsistent treatment of s=0,∞ by gammaIncomplete(s, x)
  9. Phobos Issue 11035: std.regex: multi-digit backreference silently drops the overshooting digit

dlang.org bug fixes

  1. Dlang.org Issue 4380: Documentation fullyQualifiedName duplicate
  2. Dlang.org Issue 4424: [dmd cli.d] Some words need escaping

Contributors to this release (236)

A huge thanks goes to all the awesome people who made this release possible.

previous version: 2.112.0