[libcxx-commits] [PATCH] D138268: [libcxx] Fix std::equal not accepting volatile types

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 18 04:46:39 PST 2022


philnik added inline comments.


================
Comment at: libcxx/include/__algorithm/equal.h:36
 equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
-  typedef typename iterator_traits<_InputIterator1>::value_type __v1;
-  typedef typename iterator_traits<_InputIterator2>::value_type __v2;
+  typedef typename iterator_traits<_InputIterator1>::reference __v1;
+  typedef typename iterator_traits<_InputIterator2>::reference __v2;
----------------
I think it would make more sense to refactor `__equal_to` to something like
```lang=c++
struct __equal_to {
  template <class _Tp, class _Up>
  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(_Tp&& __lhs, _Up&& __rhs) const {
    return __lhs == __rhs;
  }
};
```
This would allow us to just remove the typedefs and instead just have
```lang=c++
return std::equal(__first1, __last1, __first2, __equal_to());
```



================
Comment at: libcxx/test/libcxx/algorithms/equal.pass.cpp:1
+//===----------------------------------------------------------------------===//
+//
----------------
Instead, you should update `libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp`.


================
Comment at: libcxx/test/libcxx/algorithms/equal.pass.cpp:17-20
+// GCC 12 gives "warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]"
+#if defined(__GNUC__) && !defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
----------------
Could you file a bug against GCC and link to it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138268



More information about the libcxx-commits mailing list