www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24222] New: emplace uses wrong init value for enum

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

          Issue ID: 24222
           Summary: emplace uses wrong init value for enum
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

As of DMD 2.105.3, the following program asserts at runtime:

---
import core.lifetime;

enum E : int[5] { a = [1, 2, 3, 4, 5] }

void main()
{
    E e = void;
    emplace(&e);
    assert(e == E.init);
}
---

The message, with -checkaction=context, is

---
core.exception.AssertError bug.d(9): cast(E)  [0, 0, 0, 0, 0] != a
---

This happens because core.lifetime.emplace uses the .init value of the enum's
base type, int, to initialize `e`, rather than the .init value of the enum
itself.

--
Nov 02 2023