This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


2730. Comparison templates on enumeration types

Section:  [over.match.oper]     Status: open     Submitter: Tobias Loew     Date: 2023-05-11

Equality and relational comparisons are supported for all enumeration types, even for scoped enumerations, as specified in 12.5 [over.built] paragraph 15 and 7.6.9 [expr.rel] paragraph 6:

If both operands (after conversions) are of arithmetic or enumeration type, each of the operators shall yield true if the specified relationship is true and false if it is false.

The comparisons can be overloaded using a non-template function, for example:

  enum class F {
    a, b
  bool operator<(F,F) = delete;
  bool b = F::a < F::b;   // error, as intended

However, using a function template does not work:

  template<typename E>
  inline constexpr bool X = false;  // specialize to disable comparisons on E

  template <typename E> requires X<E>
  void operator<(E, E) = delete;

  template <>
  inline constexpr bool X<F> = true;

  bool b = F::a < F::b;             // ok, selects built-in comparison per [] bullet 2.4

The reason is that the built-in operator candidates are not suppressed if they compete with a template specialization.

Suggested resolution:

Change in [over.match.oper] bullet 3.3.4 as follows: