boost-operators

C++20 behaviour breaking existing code with equality operator?

孤街浪徒 提交于 2021-01-20 14:13:48
问题 I ran into this while debugging this question. I trimmed it down all the way to just using Boost Operators: Compiler Explorer C++17 C++20 #include <boost/operators.hpp> struct F : boost::totally_ordered1<F, boost::totally_ordered2<F, int>> { /*implicit*/ F(int t_) : t(t_) {} bool operator==(F const& o) const { return t == o.t; } bool operator< (F const& o) const { return t < o.t; } private: int t; }; int main() { #pragma GCC diagnostic ignored "-Wunused" F { 42 } == F{ 42 }; // OKAY 42 == F