public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/96851] operator< on std::array<T, N> does not work in constexpr, for sizeof(T) == 1, and N > 1 Date: Wed, 02 Sep 2020 15:42:16 +0000 [thread overview] Message-ID: <bug-96851-4-DVM7ea1BG2@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96851-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96851 --- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-10 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:33c34c4c2466fd4fd050ed8e2d5996c35ebdeef6 commit r10-8702-g33c34c4c2466fd4fd050ed8e2d5996c35ebdeef6 Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Sep 2 15:17:24 2020 +0100 libstdc++: Fix three-way comparison for std::array [PR 96851] The spaceship operator for std::array uses memcmp when the __is_byte<value_type> trait is true, but memcmp isn't usable in constexpr contexts. Also, memcmp should only be used for unsigned byte types, because it gives the wrong answer for signed chars with negative values. We can simply check std::is_constant_evaluated() so that we don't use memcmp during constant evaluation. To fix the problem of using memcmp for inappropriate types, this patch adds new __is_memcmp_ordered and __is_memcmp_ordered_with traits. These say whether using memcmp will give the right answer for ordering operations such as lexicographical_compare and three-way comparisons. The new traits can be used in several places. Unlike the trunk commit this was backported from, this commit for the branch doesn't extend the memcmp optimisations to all unsigned integers on big endian targets. Only narrow character types and std::byte will use memcmp. libstdc++-v3/ChangeLog: PR libstdc++/96851 * include/bits/cpp_type_traits.h (__is_memcmp_ordered): New trait that says if memcmp can be used for ordering. (__is_memcmp_ordered_with): Likewise, for two types. * include/bits/ranges_algo.h (__lexicographical_compare_fn): Use new traits instead of __is_byte and __numeric_traits. * include/bits/stl_algobase.h (__lexicographical_compare_aux1) (__is_byte_iter): Likewise. * include/std/array (operator<=>): Likewise. Only use memcmp when std::is_constant_evaluated() is false. * testsuite/23_containers/array/comparison_operators/96851.cc: New test. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. (cherry picked from commit 2f983fa69005b603ea1758a013b4134d5b0f24a8)
next prev parent reply other threads:[~2020-09-02 15:42 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-30 13:09 [Bug libstdc++/96851] New: " milasudril at gmail dot com 2020-08-30 13:15 ` [Bug libstdc++/96851] " milasudril at gmail dot com 2020-09-02 8:54 ` redi at gcc dot gnu.org 2020-09-02 9:08 ` redi at gcc dot gnu.org 2020-09-02 14:51 ` cvs-commit at gcc dot gnu.org 2020-09-02 15:17 ` milasudril at gmail dot com 2020-09-02 15:25 ` redi at gcc dot gnu.org 2020-09-02 15:42 ` cvs-commit at gcc dot gnu.org [this message] 2020-09-02 15:46 ` redi at gcc dot gnu.org 2021-07-12 11:14 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-96851-4-DVM7ea1BG2@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).