g++ and clang++ disagree on whether I can call a static constexpr method at compile time. Here is a small program to illustrate the difference:
#include <print>
struct foo {
static constexpr int max_size() { return 0; }
};
struct bar {
};
void
report(const char *name, const auto &&x)
{
if constexpr (requires { requires x.max_size() < 5; })
std::println("{} is okay", name);
else
std::println("{} is not okay", name);
}
int
main()
{
report("foo", foo{});
report("bar", bar{});
}
// Clang 18.1.8
// clang++ -std=c++23 -O2 -Wall -Werror constexpr.cc -o constexpr
// foo is not okay
// bar is not okay
// g++ 14.1.1
// g++ -std=c++23 -O2 -Wall -Werror constexpr.cc -o constexpr
// foo is okay
// bar is not okay
Which compiler is right?
As a workaround for this particular case, if I say decltype(auto(x))::max_size() < 5
both compilers behave like gcc in the above example.