[Issue 250] New: enum : bool allowed with odd results
Thomas Kuehne
thomas-dloop at kuehne.cn
Tue Aug 15 02:53:07 PDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
d-bugmail at 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-----
More information about the Digitalmars-d-bugs
mailing list