digitalmars.D.bugs - [Issue 196] New: Static assertion involving typedef's base type fails strangely
- d-bugmail puremagic.com (27/27) Jun 15 2006 http://d.puremagic.com/issues/show_bug.cgi?id=196
- Thomas Kuehne (27/38) Jul 07 2006 -----BEGIN PGP SIGNED MESSAGE-----
- d-bugmail puremagic.com (28/28) Jan 01 2007 http://d.puremagic.com/issues/show_bug.cgi?id=196
- d-bugmail puremagic.com (18/18) Jun 23 2008 http://d.puremagic.com/issues/show_bug.cgi?id=196
http://d.puremagic.com/issues/show_bug.cgi?id=196
Summary: Static assertion involving typedef's base type fails
strangely
Product: D
Version: 0.160
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: diagnostic, rejects-valid
Severity: major
Priority: P2
Component: DMD
AssignedTo: bugzilla digitalmars.com
ReportedBy: deewiant gmail.com
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));
--
Also, there's an extra space between "assert" and "(is" in the error message.
--
Jun 15 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 d-bugmail puremagic.com schrieb am 2006-06-15:http://d.puremagic.com/issues/show_bug.cgi?id=196I 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: The compile time check is broken: Background: 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-----
Jul 07 2006
http://d.puremagic.com/issues/show_bug.cgi?id=196
thomas-dloop kuehne.cn changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|rejects-valid |
OS/Version|Windows |All
The error message is incorrect, the assert should fail regardless.
x -> (typedef int)
typeid(x) -> TypeInfo_Typedef(x)
typeid(x).base -> TypeInfo(int)
typeof(typeid(x).base) -> TypeInfo
Thus rewriting the above assert:
To ensuring that a typedef's direct base type is an int:
--
Jan 01 2007
http://d.puremagic.com/issues/show_bug.cgi?id=196
bugzilla digitalmars.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
Thomas' code is almost correct. The correct code would be:
typedef int X;
static if (is(X base == typedef))
{
static assert(is(base == int), "base of typedef X is not int");
}
else
{
static assert(0, "X is not a typedef");
}
--
Jun 23 2008









Thomas Kuehne <thomas-dloop kuehne.cn> 