Bug 6910 – __traits(hasMember, "<name>") does not work, if template has alias param
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-08T14:29:00Z
Last change time
2015-06-09T05:11:48Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
tobias
Comments
Comment #0 by tobias — 2011-11-08T14:29:58Z
Given this code fragment:
--------------
struct Bag(S...)
{
alias S Types;
}
template Test(alias i, B)
{
void fn() {
foreach(t; B.Types)
{
switch(i) {
case IndexOf!(t, B.Types):
{
pragma(msg, __traits(allMembers, t));
pragma(msg, __traits(hasMember, t, "m"));
break;
}
default: {}
}
}
}
}
struct A
{
int m;
}
void main()
{
int i;
alias Test!(i, Bag!(A)).fn func;
}
----------------------
DMD will output:
----------------------
tuple("m")
false
---------------------
It seems that __traits(hasMember, ..) evaluates to false, despite the fact that the type
does have a member "m". However if the template Test does not have an alias parameter, everything will work just fine.