I noticed a discrepancy between C++23 and C++26 code when using googlemock:
enum A { A1, A2 };
enum B { B1, B2 };
TEST(...)
{
ASSERT_EQ(A1, B1); // compiles fine in C++23 and C++26
ASSERT_THAT(A1, Eq(B1)); // does not compile in C++26
}
/opt/compiler-explorer/libs/googletest/trunk/googletest/include/gtest/gtest-matchers.h:700:16: error: no match for call to '(std::equal_to) (const A&, const B&)'
700 | return Op()(lhs, Unwrap(rhs_));
..compilers_c++_x86_gcc_15.2.0/include/c++/15.2.0/bits/stl_function.h:496:9: note: template argument deduction/substitution failed:
This simplified google mock code translates to use A1 == B1 and std::equal_to<void>{}(A1, B1):
enum A { A1, A2 };
enum B { B1, B2 };
void foo()
{
// ASSERT_EQ(A1, B1);
if (A1 == B1) { ... } // compiles fine in C++23 and C++26
// ASSERT_THAT(A1, Eq(B1));
if (std::equal_to<void>{}(A1, B1)) { ... } // does not compile in C++26
}
See godbolt.
This only happens in gcc(g++) -- clang compiles both versions.
It is, of course, a bug in test to compare values from different enums, and it is perfect that std::equal_to<void>{} catches that.
Is this behavior mandated by C++26, or just some kind of "bug" in gcc's std lib? It works that way only in gcc(g++). Clang compiles fine both ways in C++23 and C++26.
Will A1 == B1 produce compilation errors as well in the final version of C++26, or it is not going to change?