Skip to content

Clang wrongly instantiates the operator== of a type with defaulted operator== despite its requires false #64124

Open
@AMP999

Description

According to a discussion on cpplang.slack.com , apparently, there is a bug in clang which causes the "PROBLEM" code (using =default) to be instantiated, despite its requires false.

https://godbolt.org/z/crcbr6xGz
GCC accepts this example; Clang and MSVC reject.

arthur-odwyer(@Quuxplusone):
(attn
@Nikolas Klauser
)
Where would we have to modify in the standard to get this to work as intended?
https://godbolt.org/z/nc4Kv3TT6
template
struct S {
Holder h;

#if PROBLEM
friend bool operator==(const S& s, const S& t)
requires false = default;
#else // NO PROBLEM
friend bool operator==(const S& s, const S& t)
requires false { return s.h == t.h; }
#endif
};
The "NO PROBLEM" code is quite properly never instantiated for any T, because it requires false; but the "PROBLEM" code (using =default) is instantiated, despite its requires false. Why does this happen, and can we make it not happen?

Brian Bi(@t3nsor):
I think that might be a bug in Clang. [temp.inst]/5 says that a friend function definition isn't supposed to be instantiated until "it is referenced in a context that requires a function definition to exist or if the existence of the definition affects the semantics of the program".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 concepts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions