Bug 15874 – getSymbolsByUDA fails if struct has no UDAs
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-04-04T19:16:00Z
Last change time
2016-04-06T23:21:47Z
Assigned to
nobody
Creator
uldis.kalninsh
Comments
Comment #0 by uldis.kalninsh — 2016-04-04T19:16:02Z
I think, this specific case should work, but it does not.
struct Test {
int x;
}
struct UDA {
}
unittest {
import std.traits;
static assert(getSymbolsByUDA!(Test,UDA).length == 0);
}
This fails with:
/usr/include/dlang/dmd/std/traits.d(6721): Error: array index [0] is outside array bounds [0 .. 0]
/usr/include/dlang/dmd/std/traits.d(6726): Error: template instance std.traits.getSymbolsByUDA!(Test, UDA).toSymbols!() error instantiating
The issue is that toSymbols within getSymbolsByUDA does not handles case with 0 matches. I think simple change to something like this should work:
template toSymbols(names...) {
static if (names.length == 0)
toSymbols = AliasSeq!();
else
mixin("alias toSymbols = AliasSeq!(symbol.%s, toSymbols!(names[1..$]));"
.format(names[0]));
}
Comment #1 by uldis.kalninsh — 2016-04-06T16:16:29Z