[Issue 250] New: enum : bool allowed with odd results
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 12 15:12:28 PDT 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 at digitalmars.com
ReportedBy: jpelcis at 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?
--
More information about the Digitalmars-d-bugs
mailing list