www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 250] New: enum : bool allowed with odd results

reply d-bugmail puremagic.com writes:
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?


-- 
Jul 12 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=250


jpelcis gmail.com changed:

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





Fixed DMD 0.163.

enum : bool can only have two values.


-- 
Jul 18 2006
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFE4aPDLK5blCcjpWoRAn4DAKCWFZpEASGgBc4UiH0zA84U1utXLQCgqAHi SfY3oLAt6lt8DpcJwBlei0w= =n0+o -----END PGP SIGNATURE-----
Aug 15 2006