Skip to content

[[clang::musttail]] unnecessarily errors when tail-calling non-member function from member function #119152

Open
@michael-kenzel

Description

@michael-kenzel

The following example fails to compile:

struct A
{
    void fun(int x);
};

void blub(A*, int);

void A::fun(int x)
{
    [[clang::musttail]] return blub(this, x);  // error: non-static member function cannot perform a tail call to non-member function 'blub'
}

This is, however, unnecessary. On many targets, a tail call would be perfectly possible here. In fact, clang will happily generate a tail call if the attribute is removed: https://godbolt.org/z/xKbcf71EM. gcc accepts this example: https://godbolt.org/z/d3f6b1b5c.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"rejects-valid

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions