I was experimenting with using arbitrary functions in fold expressions, when I found the following code that compiles with gcc
but does not compile with clang
.
enum Enum {
A = 3,
B = 8,
C = 5
};
namespace EnumMax {
constexpr Enum operator>>=(const Enum left, const Enum right) {
return left < right ? right : left;
}
}
template<Enum ... enums>
constexpr Enum max() {
using EnumMax::operator>>=;
return (enums >>= ...);
}
constexpr Enum max_v = max<A, B, C>();
It seems that clang
does not consider the overloaded operator, but attempts to use the regular >>=
operator in the fold expression.
However, if instead the fold expression is spelled out, clang
does consider the overloaded operator and will compile just fine:
constexpr Enum maxExplicit() {
using EnumMax::operator>>=;
return (A >>= (B >>= C));
}
Is this a clang
bug? Or is the spelled out equivalent of a fold expression not exactly equivalent?