Skip to content

[Clang][Sema][Concepts] Clang can't choose from a member and a non member operator #82509

@HoBoIs

Description

@HoBoIs

Consider the following code:

struct s{
    template<class T>
    int operator+(const T&)const{return 0;}
};

template<class T>
concept AlwaysTrue=true;

template<AlwaysTrue T>
int operator+(const s&,const T&){return 1;}

int main(){
    return s{}+1;
}

godbolt example: https://godbolt.org/z/vG31vjxbn
Since the 2nd operator+ is more constrained clang should choose that. However clang reports an ambiguity. (GCC chooses the 2nd one as expected)
Note that the ambiguity remains if the only 1st, or both declaration have a concept, (even if one of them is more constrained).
If we define both operators inside the class or both operators outside the class clang chooses the correct overload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsconfirmedVerified by a second party

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions