www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inferred enum base types


When compiling following code with dmd (v2.051)

enum nums {  X = 'a', Y, Z }

void main() {
  nums q;
  char w;
  w = q;

I get 'Error: cannot implicitly convert expression (q) of type nums to char'
for the 'w = q' assigment.

Should'n the inferred base type for 'nums' be char, given that the first
'nums' member is initilized with char literal 'a'?

When the nums declaration is changed to:

enum nums : char {  X = 'a', Y, Z }

the code compiles without errors.

It seems that when enums base type is allways inferred to int. Am I missing
something or is it an DMD bug?

Oct 14 2011