D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21785 - Cannot declare variable of opaque enum with base type
Summary: Cannot declare variable of opaque enum with base type
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: diagnostic, pull
Depends on:
Blocks:
 
Reported: 2021-03-30 23:57 UTC by moonlightsentinel
Modified: 2021-04-04 02:02 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description moonlightsentinel 2021-03-30 23:57:45 UTC
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 moonlightsentinel 2021-04-02 19:07:00 UTC
(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 Dlang Bot 2021-04-02 20:29:20 UTC
@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 Dlang Bot 2021-04-04 02:02:14 UTC
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