libstdc++: Fix bogus use of memcmp in ranges::lexicographical_compare (PR 93972)
authorPatrick Palka <ppalka@redhat.com>
Fri, 28 Feb 2020 19:16:06 +0000 (14:16 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 28 Feb 2020 22:55:44 +0000 (17:55 -0500)
commitce33801fe4c2272b31c64288b34c67a61529ce37
tree60a5ff84a1d13e63770f1fafbed63864e92043c2
parente82192021dd08291ee418cb33bb7af037952e963
libstdc++: Fix bogus use of memcmp in ranges::lexicographical_compare (PR 93972)

We were enabling the memcmp optimization in ranges::lexicographical_compare for
signed integral types and for integral types wider than a byte.  But memcmp
gives the wrong answer for arrays of such types.  This patch fixes this issue by
refining the condition that enables the memcmp optimization.  It's now
consistent with the corresponding condition used in
std::lexicographical_compare.

libstdc++-v3/ChangeLog:

PR libstdc++/93972
* include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()):
Fix condition for when to use memcmp, making it consistent with the
corresponding condition used in std::lexicographical_compare.
* testsuite/25_algorithms/lexicographical_compare/93972.cc: New test.
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/ranges_algo.h
libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/93972.cc [new file with mode: 0644]