www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inferred enum base types

--20cf300512bcce941004af46afc4
Content-Type: text/plain; charset=UTF-8

Hi

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?

/lennart

--20cf300512bcce941004af46afc4
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div>Hi</div><div><br></div><div>When compiling following code with dmd (v2=
.051)</div><div><br></div><div>enum nums { =C2=A0X =3D &#39;a&#39;, Y, Z }<=
/div><div><br></div><div>void main() {</div><div>=C2=A0 nums q;</div><div>=
=C2=A0 char w;</div>
<div>=C2=A0 w =3D q;</div><div>}</div><div><br></div><div>I get &#39;Error:=
 cannot implicitly convert expression (q) of type nums to char&#39; for the=
 &#39;w =3D q&#39; assigment.</div><div><br></div><div>Should&#39;n the inf=
erred base type for &#39;nums&#39; be char, given that the first &#39;nums&=
#39; member is initilized with char literal &#39;a&#39;?</div>
<div><br></div><div>When the nums declaration is changed to:</div><div><br>=
</div><div>enum nums : char { =C2=A0X =3D &#39;a&#39;, Y, Z }</div><div><br=
</div><div>the code compiles without errors.</div><div><br></div><div>It s=

ething or is it an DMD bug?</div> <div><br></div><div>/lennart</div> --20cf300512bcce941004af46afc4--
Oct 14 2011