Thread overview
[Issue 250] New: enum : bool allowed with odd results
Jul 12, 2006
d-bugmail
Jul 18, 2006
d-bugmail
Aug 15, 2006
Thomas Kuehne
July 12, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=250

           Summary: enum : bool allowed with odd results
           Product: D
           Version: 0.162
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: jpelcis@gmail.com


module test;

import std.stdio;

enum Bool : bool {
        False,
        True,
        Unknown
}

void main () {
        writefln("The maximum value of bool is %d.", bool.max);
        writefln("The maximum value of Bool is %d.", cast(int)Bool.max);
        writefln("    Also, should that cast be necessary?\n");

        writefln("Using 2 as a bool gives %d.", cast(bool)2);
        writefln("Using 2 as a Bool gives %d.", cast(int)cast(Bool)2);
        writefln("Using Bool.Unknown as an int gives %d.",
cast(int)Bool.Unknown);
        writefln("Using Bool.Unknown as a bool gives %d.",
cast(bool)Bool.Unknown);
}

-----------------------------

Running this gives me the following data:

-----------------------------

The maximum value of bool is 1.
The maximum value of Bool is 1.
    Also, should that cast be necessary?

Using 2 as a bool gives 1.
Using 2 as a Bool gives 1.
Using Bool.Unknown as an int gives 1.
Using Bool.Unknown as a bool gives 2.

-----------------------------

This is either accepts-invalid or wrong-code, depending on whether enum : bool is legal.

Also, I must admit to being curious why casting Bool.Unknown to an int gives 1 while casting it to a bool gives 2.  Is cast ignored for enum to base type?


-- 

July 18, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=250


jpelcis@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from jpelcis@gmail.com  2006-07-18 16:33 -------
Fixed DMD 0.163.

enum : bool can only have two values.


-- 

August 15, 2006
d-bugmail@puremagic.com schrieb am 2006-07-12:
> http://d.puremagic.com/issues/show_bug.cgi?id=250

> module test;
>
> import std.stdio;
>
> enum Bool : bool {
>         False,
>         True,
>         Unknown
> }
>
> void main () {
>         writefln("The maximum value of bool is %d.", bool.max);
>         writefln("The maximum value of Bool is %d.", cast(int)Bool.max);
>         writefln("    Also, should that cast be necessary?\n");
>
>         writefln("Using 2 as a bool gives %d.", cast(bool)2);
>         writefln("Using 2 as a Bool gives %d.", cast(int)cast(Bool)2);
>         writefln("Using Bool.Unknown as an int gives %d.",
> cast(int)Bool.Unknown);
>         writefln("Using Bool.Unknown as a bool gives %d.",
> cast(bool)Bool.Unknown);
> }
>
> -----------------------------
>
> Running this gives me the following data:
>
> -----------------------------
>
> The maximum value of bool is 1.
> The maximum value of Bool is 1.
>     Also, should that cast be necessary?
>
> Using 2 as a bool gives 1.
> Using 2 as a Bool gives 1.
> Using Bool.Unknown as an int gives 1.
> Using Bool.Unknown as a bool gives 2.
>
> -----------------------------
>
> This is either accepts-invalid or wrong-code, depending on whether enum : bool is legal.
>
> Also, I must admit to being curious why casting Bool.Unknown to an int gives 1 while casting it to a bool gives 2.  Is cast ignored for enum to base type?

Added to DStress as http://dstress.kuehne.cn/nocompile/e/enum_46_A.d http://dstress.kuehne.cn/compile/e/enum_46_B.d http://dstress.kuehne.cn/compile/e/enum_46_C.d http://dstress.kuehne.cn/compile/e/enum_46_D.d http://dstress.kuehne.cn/compile/e/enum_46_E.d

Thomas