www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20758] New: __traits(getAttributes) as template argument

https://issues.dlang.org/show_bug.cgi?id=20758

          Issue ID: 20758
           Summary: __traits(getAttributes) as template argument results
                    in broken template instances
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

template foo(a...) {
    static int x;
}

void attr1() {}

// enum attr2 = 1;
// struct attr3 {}

 attr1 int x;

alias f1 = foo!attr1;
alias f2 = foo!(__traits(getAttributes, x));

// passes
static assert(f1.mangleof == f2.mangleof);

// fails, should pass
static assert(__traits(isSame, f1, f2));

void main() {
    auto p1 = &f1.x;
    auto p2 = &f2.x;

    // passes
    assert(p1 == p2);

    // but this fails
    assert(&f1.x == &f2.x);
}


The bug seems to manifest only for attributes that are functions. If attr1 is
replaced with attr2 or attr3, the assertions pass.

--
Apr 22 2020