在可以访问私有运算符 == 的上下文中进行 std::equality_comparable 概念检查

Fed*_*dor 6 c++ private language-lawyer c++-concepts c++20

std::equality_comparable允许人们检查类对象是否可以使用==and!=运算符进行比较。但是,如果运算符存在但并非在所有上下文中都可用,它会返回什么?

下一个程序A::operator ==是私有的,只能在朋友功能中访问f。如果检查之前std::equality_comparable<A>的内容,那么它的正文也将是错误的:falseff

#include <concepts>

class A {
    bool operator ==(const A&) const = default;
    friend void f();
};

static_assert( !std::equality_comparable<A> );
void f() {
    static_assert( !std::equality_comparable<A> );
}
Run Code Online (Sandbox Code Playgroud)

这被 GCC、Clang 和 MSVC 接受,演示: https: //gcc.godbolt.org/z/Yqc38zobf

但如果首先在 GCC 和 Clang 中测试这个概念,f那么它将是,并且将在之后true保留:truef

class A {
    bool operator ==(const A&) const = default;
    friend void f();
};

void f() {
    static_assert( std::equality_comparable<A> );
}
static_assert( std::equality_comparable<A> );

Run Code Online (Sandbox Code Playgroud)

std::equality_comparable<A>==false这里只有MSVC还考虑,demo:https: //gcc.godbolt.org/z/Ko3Kqc9x7

这里是哪个编译器?