[Issue 24222] New: emplace uses wrong init value for enum
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 3 00:55:55 UTC 2023
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 at puremagic.com
Reporter: snarwin+bugzilla at 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 at 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.
--
More information about the Digitalmars-d-bugs
mailing list