Bug 21785 – Cannot declare variable of opaque enum with base type
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-03-30T23:57:45Z
Last change time
2021-04-04T02:02:14Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
moonlightsentinel
Comments
Comment #0 by moonlightsentinel — 2021-03-30T23:57:45Z
The following code doesn't compile unless `var` is void-initialized:
--------------------------------------
enum Xobj : void*;
void main()
{
Xobj var;
}
--------------------------------------
Error: enum enum_init.Xobj forward reference of Xobj.init
There is no forward reference involved and `var` can just be initialized by `void.init`.
Comment #1 by moonlightsentinel — 2021-04-02T19:07:00Z
(In reply to moonlightsentinel from comment #0)
> [...] `var` can just be initialized by `void*.init`.
This isn't correct for all opaque enums so the code is rightfully rejected.
Added `diagnostic` because the error message is wrong.
Comment #2 by dlang-bot — 2021-04-02T20:29:20Z
@MoonlightSentinel updated dlang/dmd pull request #12325 "Fix 21785 - Improve error messages for opaque enums" fixing this issue:
- Fix 21785 - Improve error messages for opaque enums
The error messages for default initialized variables of opaque enums
were horrid and contained misleading informations.
This PR removes them by by checking whether semantic was already
run in case of an enum without members.
Some examples:
```d
enum NoBase;
enum WithBase : long;
// Not handled yet
struct S;
enum OpaqueBase : S;
void main()
{
NoBase nb;
WithBase wb;
OpaqueBase ob;
}
```
https://github.com/dlang/dmd/pull/12325
Comment #3 by dlang-bot — 2021-04-04T02:02:14Z
dlang/dmd pull request #12325 "Fix 21785 - Improve error messages for opaque enums" was merged into master:
- 92d1d59eb61f776e98b28deb75b6f64374b0e03b by MoonlightSentinel:
Fix 21785 - Improve error messages for opaque enums
The error messages for default initialized variables of opaque enums
were horrid and contained misleading informations.
This PR removes them by by checking whether semantic was already
run in case of an enum without members.
Some examples:
```d
enum NoBase;
enum WithBase : long;
// Not handled yet
struct S;
enum OpaqueBase : S;
void main()
{
NoBase nb;
WithBase wb;
OpaqueBase ob;
}
```
https://github.com/dlang/dmd/pull/12325