www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22711] New: Effect of template UDAs on instance members is


          Issue ID: 22711
           Summary: Effect of template UDAs on instance members is
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dlang.org
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

When a UDA is attached to a template declaration, and that template is
instantiated, the UDA is automatically attached to each of that template
instance's direct members:

 ("uda") template Example(T)
    struct S { int x; }
    int n;
    void fun() {};

import std.traits: hasUDA;

static assert(hasUDA!(Example!int.S, "uda"));
static assert(hasUDA!(Example!int.n, "uda"));
static assert(hasUDA!(Example!int.fun, "uda"));

// does not apply to members of members
static assert(!hasUDA!(Example!int.S.x, "uda"));

However, this behavior is not documented in the language spec.

Jan 28 2022