Bug 24850 – Named enum construction from base type is inconsistent

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-11-09T16:35:12Z
Last change time
2024-12-13T19:38:27Z
Assigned to
No Owner
Creator
Nick Treleaven
Moved to GitHub: dmd#20543 →

Comments

Comment #0 by nick — 2024-11-09T16:35:12Z
The following is an error: ``` enum E : int; E e = E(4); ``` enumbase.d(2): Error: cannot implicitly convert expression `4` of type `int` to `E` Which is consistent with uniform construction because a base type instance does not implicitly convert to the enum type. But this compiles: ``` struct S { this(int) {} } enum E : S; E e = E(2); ``` However, an instance of S does not implicitly convert to E, so this is inconsistent. The spec does not seem to mention enum construction with an argument list. There is a test in dmd for issue 16346 to allow E(E.member), presumably for generic code.
Comment #1 by nick — 2024-11-09T17:28:53Z
There is also a dmd test case for issue 23778 using construction from base struct. So it would need to be deprecated.
Comment #2 by robert.schadek — 2024-12-13T19:38:27Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20543 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB