Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/denum.d
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,14 @@ extern (C++) final class EnumMember : VarDeclaration
protection = ed.isAnonymous() ? ed.protection : Prot(PROTpublic);
linkage = LINKd;
storage_class = STCmanifest;
userAttribDecl = ed.isAnonymous() ? ed.userAttribDecl : null;

if(ed.isAnonymous())
{
if(userAttribDecl)
userAttribDecl.userAttribDecl = ed.userAttribDecl;
else
userAttribDecl = ed.userAttribDecl;
}

semanticRun = PASSsemantic;

Expand Down
13 changes: 13 additions & 0 deletions src/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,17 @@ final class Parser : Lexer

Type type = null;
Identifier ident = null;
Expressions* udas = null;

while(token.value == TOKat)
{
if(StorageClass stc = parseAttribute(&udas))
{
error("only user defined attributes can appear in enums, not %s", stcToChars(stc));
nextToken();
}
}

Token* tp = peek(&token);
if (token.value == TOKidentifier && (tp.value == TOKassign || tp.value == TOKcomma || tp.value == TOKrcurly))
{
Expand Down Expand Up @@ -3007,6 +3018,8 @@ final class Parser : Lexer
}

auto em = new EnumMember(loc, ident, value, type);
if(udas)
em.userAttribDecl = new UserAttributeDeclaration(udas, new Dsymbols());
e.members.push(em);

if (token.value == TOKrcurly)
Expand Down
25 changes: 25 additions & 0 deletions test/compilable/test9701.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import std.meta;

enum Enum
{
withoutUda,
@("first") valueWithUda,
@("second", "extra", 3) secondValueWithUda,
}

@("outter")
enum
{
@("first") anonFirst,
anonSecond,
@("third") @("extra") anonThird,
}

static assert(__traits(getAttributes, Enum.withoutUda).length == 0);
static assert(__traits(getAttributes, Enum.valueWithUda) == AliasSeq!("first"));
static assert(__traits(getAttributes, Enum.secondValueWithUda) == AliasSeq!("second", "extra", 3));

static assert(__traits(getAttributes, anonFirst) == AliasSeq!("outter", "first"));
static assert(__traits(getAttributes, anonSecond) == AliasSeq!("outter"));
static assert(__traits(getAttributes, anonThird) == AliasSeq!("outter", "third", "extra"));
12 changes: 12 additions & 0 deletions test/fail_compilation/fail9701.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
TEST_OUTPUT
---
fail_compilation/fail9701.d(11): Error: only user defined attributes can appear in enums, not @nogc
fail_compilation/fail9701.d(11): Error: only user defined attributes can appear in enums, not @disable
---
*/

enum Enum
{
@("string") @nogc @(117) @disable @("value", 2525) value,
}