[Issue 196] New: Static assertion involving typedef's base type fails strangely

Thomas Kuehne thomas-dloop at kuehne.cn
Fri Jul 7 06:12:17 PDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail at puremagic.com schrieb am 2006-06-15:
> http://d.puremagic.com/issues/show_bug.cgi?id=196

> I need to static assert that a typedef's base type is equal to int.
>
> I tried the code below, but it fails with the message "static assert  (is(int
>== int)) is false". If this is not meant to work, this is a bug in the sense
> that the error message makes no sense; if this is meant to work, it's a bug in
> the sense that it doesn't work.
>
> In the former case, feel free to change the priority, severity, and keywords to
> match: I'm currently assuming that this should work.
>
> --
> typedef int x;
>
> static assert (is (typeof(typeid(x).base) == int));

typeid(x).base is an TypeInfo_Typedef object downcasted to TypeInfo.

Checking the base at runtime:
#
# assert( is(x == typedef)
#	&& (cast(TypeInfo_Typedef)typeid(x)).base.toString() == "int);
#

The compile time check is broken:
#
# // should only succed for int and uint as base types
# static assert(is(x : int) && (! is(x : short)));
#

Background:
#
# static assert(is(int : short));
#
Succeeds, but should fail if D were a strict language. Sadly the "Usual
Arithmetic Conversions" section from http://digitalmars.com/d/type.html
only talks about operand and not about types :(

Thomas

-----BEGIN PGP SIGNATURE-----

iD8DBQFErl1yLK5blCcjpWoRAs8BAJsEDWAqPecADZP40/2InKbBjqsAEQCdFz71
axl0WwkYVb1LfP83dgjkEvE=
=VliI
-----END PGP SIGNATURE-----



More information about the Digitalmars-d-bugs mailing list