Skip to content

Commit bf07ff0

Browse files
authored
Merge pull request #3195 from pbackus/fix-22711
Fix issue 22711 - Effect of template UDAs on instance members is undo…
2 parents 0debbf8 + 1f116dd commit bf07ff0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

spec/attribute.dd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,42 @@ pragma(msg, __traits(getAttributes, typeof(a))); // prints tuple("hello")
788788
attributes accumulate or override earlier ones is also up to how the user
789789
interprets them.
790790
)
791+
792+
$(P
793+
If a UDA is attached to a template declaration, then it will be automatically
794+
attached to all direct members of instances of that template. If any of those
795+
members are templates themselves, this rule applies recursively:
796+
)
797+
798+
---
799+
@("foo") template Outer(T)
800+
{
801+
struct S
802+
{
803+
int x;
804+
}
805+
int y;
806+
void fun() {}
807+
@("bar") template Inner(U)
808+
{
809+
int z;
810+
}
811+
}
812+
813+
pragma(msg, __traits(getAttributes, Outer!int.S));
814+
// prints tuple("foo")
815+
pragma(msg, __traits(getAttributes, Outer!int.S.x));
816+
// prints tuple()
817+
pragma(msg, __traits(getAttributes, Outer!int.y));
818+
// prints tuple("foo")
819+
pragma(msg, __traits(getAttributes, Outer!int.fun));
820+
// prints tuple("foo")
821+
pragma(msg, __traits(getAttributes, Outer!int.Inner));
822+
// prints tuple("foo", "bar")
823+
pragma(msg, __traits(getAttributes, Outer!int.Inner!int.z));
824+
// prints tuple("foo", "bar")
825+
---
826+
791827
$(P
792828
UDAs cannot be attached to template parameters.
793829
)

0 commit comments

Comments
 (0)