Skip to content

Commit

Permalink
Merge pull request #4164 from Ukalnins/issue_15874
Browse files Browse the repository at this point in the history
Fix Issue 15874 - getSymbolsByUDA fails if struct has no UDAs
  • Loading branch information
Hackerpilot committed Apr 6, 2016
2 parents ed962c7 + f7359a8 commit cf4f09f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions std/traits.d
Expand Up @@ -6723,8 +6723,8 @@ template getSymbolsByUDA(alias symbol, alias attribute) {
// translate a list of strings into symbols. mixing in the entire alias
// avoids trying to access the symbol, which could cause a privacy violation
template toSymbols(names...) {
static if (names.length == 1)
mixin("alias toSymbols = AliasSeq!(symbol.%s);".format(names[0]));
static if (names.length == 0)
alias toSymbols = AliasSeq!();
else
mixin("alias toSymbols = AliasSeq!(symbol.%s, toSymbols!(names[1..$]));"
.format(names[0]));
Expand Down Expand Up @@ -6796,6 +6796,14 @@ unittest
static assert(getSymbolsByUDA!(C, UDA).length == 2);
static assert(getSymbolsByUDA!(C, UDA)[0].stringof == "C");
static assert(getSymbolsByUDA!(C, UDA)[1].stringof == "d");

static struct D
{
int x;
}

//Finds nothing if there is no member with specific UDA
static assert(getSymbolsByUDA!(D,UDA).length == 0);
}

// #15335: getSymbolsByUDA fails if type has private members
Expand Down

0 comments on commit cf4f09f

Please sign in to comment.