D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11905 - Can't make enum of custom struct types autoincrement working
Summary: Can't make enum of custom struct types autoincrement working
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-11 12:28 UTC by Daniel Čejchan
Modified: 2023-02-11 07:34 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Daniel Čejchan 2014-01-11 12:28:35 UTC
http://pastebin.com/cnKy8LGK

Such thing causes "Error: no property 'max' for type 'enumf!ushort'" error (no error line or anything).
I have tried implementing my own max using enum, static immutable variable, @property function and static @property function, either one does not work (throws "Error: no property 'max' for type 'enumf!ushort', did you mean 'max'?").
Comment 1 Daniel Čejchan 2014-01-11 14:57:42 UTC
CyberShadow has made a patch that should fix this: http://dump.thecybershadow.net/88e4ac8353cebe100f9379da688829e0/opt-max-check.patch
Comment 2 basile-z 2023-02-11 07:34:09 UTC
This is working since 2.099 and the test suite contains a similar test to

---
struct enumf( T = ushort ) {

    enum max = T.max;


  alias val this;
  T val = 1;
  this( T val ) {
    this.val = val;
  }
  this( int val ) {
    this.val = cast( T ) val;
  }

  void opAssign( int val ) {
    this.val = cast( T ) val;
  }

  enumf!T opBinary( string op : "+" )( T add ) {
    return enumf!T( val << add );
  }

  int opCmp( enumf!T other ) {
    if( other.val == val )
      return 0;
    else if( val > other.val )
      return 1;
    else
      return -1;
  }

}

enum F {
  halCenter = enumf!ushort(),
  halRight,
  valCenter = enumf!ushort( 2 ),
  valRight = enumf!ushort( 1 )
}   
---