<br><br><div class="gmail_quote">On Fri, Oct 14, 2011 at 9:00 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com">jmdavisProg@gmx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Friday, October 14, 2011 20:47:12 Lennart Blanco wrote:<br>
> Hi<br>
><br>
> When compiling following code with dmd (v2.051)<br>
><br>
> enum nums {  X = 'a', Y, Z }<br>
><br>
> void main() {<br>
>   nums q;<br>
>   char w;<br>
>   w = q;<br>
> }<br>
><br>
> I get 'Error: cannot implicitly convert expression (q) of type nums to char'<br>
> for the 'w = q' assigment.<br>
><br>
> Should'n the inferred base type for 'nums' be char, given that the first<br>
> 'nums' member is initilized with char literal 'a'?<br>
><br>
> When the nums declaration is changed to:<br>
><br>
> enum nums : char {  X = 'a', Y, Z }<br>
><br>
> the code compiles without errors.<br>
><br>
> It seems that when enums base type is allways inferred to int. Am I missing<br>
> something or is it an DMD bug?<br>
<br>
</div></div>I believe that the answer is that there is effectively no inferrence when you<br>
give a list of enum values (rather than declaring a manifest constant), and it<br>
is always assumed to be int unless you declare it to be otherwise.<br><br></blockquote><div><br></div><div>The reason I expected the base type to be inferred to char is because the language spec (<a href="http://d-programming-language.org/enum.html">http://d-programming-language.org/enum.html</a>) says:</div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>"If the EnumBaseType is not explicitly set, and the first EnumMember has an initializer, it is set to the type of that initializer. Otherwise, it defaults to type int."</div>
<div><br></div><div>I have now checked TDPL book and there it only says 'The type of named enum is automatically deduced as int'. No mention of using first enum member initializer for deducing the base type.</div>
<div><br></div><div>Perhaps the problem is that language spec need to be updated?</div><div><br></div><div>/lennart</div><meta http-equiv="content-type" content="text/html; charset=utf-8"></div>