[Issue 15874] New: getSymbolsByUDA fails if struct has no UDAs
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Apr 4 12:16:02 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15874
Issue ID: 15874
Summary: getSymbolsByUDA fails if struct has no UDAs
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: minor
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: uldis.kalninsh at gmail.com
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]));
}
--
More information about the Digitalmars-d-bugs
mailing list