Skip to content

Can't instantiate template from __traits(getOverloads, ...) #22357

@TurkeyMan

Description

@TurkeyMan
struct Test
{
    void fn(int) {}
    void fn()(float) {} // template overload
}

void test()
{
    Test t;
    void delegate(int) fnptr = &__traits(getOverloads, t, "fn", true)[0];
    void delegate(float) tfnptr = &__traits(getOverloads, t, "fn", true)[1]!(); // error : semicolon needed to end declaration of `tfnptr` instead of `!`

    // you can see above when we try and instantiate the template given by getOverloads, it seems the grammar just doesn't accept it!

    // ...but really, the main issue leading here is another case of `alias` not working as people expect:
    alias fn = __traits(getOverloads, t, "fn", true)[0]; // error : alias `fn` cannot alias an expression `t.fn`
    alias tfn = __traits(getOverloads, t, "fn", true)[1]; // error : alias `tfn` cannot alias an expression `t.fn()(float)`

    fnptr = &fn;
    tfnptr = &tfn!();
}

I think this whole block of code should compile; the template instanton issue, and also the "alias not working as expected" issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions