[libcxx-commits] [PATCH] D144262: [libc++][ranges] Implement LWG-3865 Sorting a range of pairs

Alexander Kornienko via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 16 09:40:52 PDT 2023


alexfh added a comment.
Herald added a subscriber: mikhail.ramalho.

The following snippet (reduced from a version of mysql) compiles well before this commit and fails to compile after it (https://gcc.godbolt.org/z/zrGbbbWb5):

  #include <utility>
  
  struct X {};
  struct Y {};
  
  bool operator==(const std::pair<const X, const X> &a, const std::pair<Y, Y> &b);
  
  bool f(std::pair<const X, X> x, std::pair<Y, Y> y) {
    return x == y;
  }

The error is:

  In file included from bin/../include/c++/v1/utility:259:
  bin/../include/c++/v1/__utility/pair.h:432:22: error: invalid operands to binary expression ('const X' and 'const Y')
      return __x.first == __y.first && __x.second == __y.second;
             ~~~~~~~~~ ^  ~~~~~~~~~
  <source>:9:12: note: in instantiation of function template specialization 'std::operator==<const X, X, Y, Y>' requested here
    return x == y;
             ^
  <source>:6:6: note: candidate function not viable: no known conversion from 'const X' to 'const std::pair<const X, const X>' for 1st argument
  bool operator==(const std::pair<const X, const X> &a, const std::pair<Y, Y> &b);
       ^
  bin/../include/c++/v1/__utility/pair.h:430:1: note: candidate template ignored: could not match 'const pair<_T1, _T2>' against 'const X'
  operator==(const pair<_T1,_T2>& __x, const pair<_U1,_U2>& __y)
  ^

I can fix this by changing the custom operator== declaration to `bool operator==(const std::pair<const X, X> &a, const std::pair<Y, Y> &b);` (removing the second `const`), but I wonder if this sort of a breakage is intended.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144262/new/

https://reviews.llvm.org/D144262



More information about the libcxx-commits mailing list