[Issue 23904] New: Spurious "struct [...] already exists"

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 8 00:29:17 UTC 2023


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

          Issue ID: 23904
           Summary: Spurious "struct [...] already exists"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dlang-bugzilla at thecybershadow.net

//////////// test.d ///////////
template f1(alias fun)
{
    struct UnusedButConflicting
    {
    }

    auto f1()
    {
    }
}

template f2(T)
{
    alias fun = {};

    auto f2(auto ref T)
    {
        f1!fun();
    }
}

auto f3(T)(T value)
{
    f2(value);
}

void main()
{
    f2(5);
    f3(5);
}
///////////////////////////////

Output:

test.d(3): Error: struct `test.f1!(function ()
{
}
).UnusedButConflicting` already exists at test.d(3). Perhaps in another
function with the same name?
test.d(18): Error: template instance `test.f1!(function ()
{
}
)` error instantiating
test.d(24):        instantiated from here: `f2!int`
test.d(30):        instantiated from here: `f3!int`
-----


I think the "auto ref" is somehow to blame. The type is the same, but the "auto
ref" is instantiated to with/without ref, which seems to cause two
UnusedButConflicting instances with the same mangling?

--


More information about the Digitalmars-d-bugs mailing list