diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-02-23 09:30:18 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-02-23 09:30:18 +0100 |
commit | efa64fcce12074dd542670feb02eaee53e810a30 (patch) | |
tree | c1d85e438b35907b89ec33679e9f3ea3e0d610ba /gcc/fold-const.c | |
parent | 7e647d71d556b73e84f4edd0733bcc83bc70ae1e (diff) | |
download | gcc-efa64fcce12074dd542670feb02eaee53e810a30.zip gcc-efa64fcce12074dd542670feb02eaee53e810a30.tar.gz gcc-efa64fcce12074dd542670feb02eaee53e810a30.tar.bz2 |
libstdc++: Fix up constexpr std::char_traits<char>::compare [PR99181]
Because of LWG 467, std::char_traits<char>::lt compares the values
cast to unsigned char rather than char, so even when char is signed
we get unsigned comparision. std::char_traits<char>::compare uses
__builtin_memcmp and that works the same, but during constexpr evaluation
we were calling __gnu_cxx::char_traits<char_type>::compare. As
char_traits::lt is not virtual, __gnu_cxx::char_traits<char_type>::compare
used __gnu_cxx::char_traits<char_type>::lt rather than
std::char_traits<char>::lt and thus compared chars as signed if char is
signed.
This change fixes it by inlining __gnu_cxx::char_traits<char_type>::compare
into std::char_traits<char>::compare by hand, so that it calls the right
lt method.
2021-02-23 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/99181
* include/bits/char_traits.h (char_traits<char>::compare): For
constexpr evaluation don't call
__gnu_cxx::char_traits<char_type>::compare but do the comparison loop
directly.
* testsuite/21_strings/char_traits/requirements/char/99181.cc: New
test.
Diffstat (limited to 'gcc/fold-const.c')
0 files changed, 0 insertions, 0 deletions