[libcxx-commits] [PATCH] D93562: [libc++] Add a missing `<_Compare>` template argument.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 18 12:55:58 PST 2020


Quuxplusone created this revision.
Quuxplusone added a reviewer: ldionne.
Quuxplusone added a project: libc++.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Sometimes `_Compare` is an lvalue reference type, so letting it be deduced is pretty much always wrong. (Well, less efficient than it could be, anyway.)

I did a manual audit for other offending calls (and I found none), by manually replacing `_Compare __comp` with a non-deducible `typename __identity<_Compare>::type __comp` in all the helper functions. My impression is that such a blanket change to the helpers would be unwelcome because it's so icky-looking. And perhaps also because it's an ABI break, in the sense that it would affect the mangling of the `__sort` specializations explicitly instantiated in src/algorithm.cpp — it's unclear to me whether we would care about that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93562

Files:
  libcxx/include/algorithm


Index: libcxx/include/algorithm
===================================================================
--- libcxx/include/algorithm
+++ libcxx/include/algorithm
@@ -4483,7 +4483,7 @@
         value_type* __p = __buff;
         for (_BidirectionalIterator __i = __first; __i != __middle; __d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
             ::new ((void*)__p) value_type(_VSTD::move(*__i));
-        _VSTD::__half_inplace_merge(__buff, __p, __middle, __last, __first, __comp);
+        _VSTD::__half_inplace_merge<_Compare>(__buff, __p, __middle, __last, __first, __comp);
     }
     else
     {
@@ -4492,9 +4492,10 @@
             ::new ((void*)__p) value_type(_VSTD::move(*__i));
         typedef reverse_iterator<_BidirectionalIterator> _RBi;
         typedef reverse_iterator<value_type*> _Rv;
-        _VSTD::__half_inplace_merge(_Rv(__p), _Rv(__buff),
+        typedef __invert<_Compare> _Inverted;
+        _VSTD::__half_inplace_merge<_Inverted>(_Rv(__p), _Rv(__buff),
                                     _RBi(__middle), _RBi(__first),
-                                    _RBi(__last), _VSTD::__invert<_Compare>(__comp));
+                                    _RBi(__last), _Inverted(__comp));
     }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93562.312875.patch
Type: text/x-patch
Size: 1234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201218/8feb41f5/attachment.bin>


More information about the libcxx-commits mailing list