diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-03-02 17:03:28 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-03-02 17:03:28 +0000 |
commit | d112e173ea093f55a16a14b26ef65088381ee09c (patch) | |
tree | 0e431eed743ba1cc0e82d88a7b3fcc79b66d8b1f /libstdc++-v3/include | |
parent | 4c391563407aeba981f6a71423297f36d5ece0ee (diff) | |
download | gcc-d112e173ea093f55a16a14b26ef65088381ee09c.zip gcc-d112e173ea093f55a16a14b26ef65088381ee09c.tar.gz gcc-d112e173ea093f55a16a14b26ef65088381ee09c.tar.bz2 |
libstdc++: Fix std::lexicographic_compare for unsigned char (PR 93972)
The new 25_algorithms/lexicographical_compare/93972.cc test fails on
targets where char is unsigned, revealing an existing regression with
the std::__memcmp helper that had gone unnoticed in
std::lexicographical_compare. When comparing char and unsigned char, the
memcmp optimisation is enabled, but the new std::__memcmp function fails
to compile for mismatched types.
PR libstdc++/93972
* include/bits/stl_algobase.h (__memcmp): Allow pointer types to
differ.
* testsuite/25_algorithms/lexicographical_compare/uchar.cc: New test.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/stl_algobase.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 5ec2f25..7a9d932 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -84,11 +84,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * A constexpr wrapper for __builtin_memcmp. * @param __num The number of elements of type _Tp (not bytes). */ - template<typename _Tp> + template<typename _Tp, typename _Up> _GLIBCXX14_CONSTEXPR inline int - __memcmp(const _Tp* __first1, const _Tp* __first2, size_t __num) + __memcmp(const _Tp* __first1, const _Up* __first2, size_t __num) { +#if __cplusplus >= 201103L + static_assert(sizeof(_Tp) == sizeof(_Up), "can be compared with memcmp"); +#endif #ifdef __cpp_lib_is_constant_evaluated if (std::is_constant_evaluated()) { |