public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "milasudril at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/96851] New: operator< on std::array<T, N> does not work in constexpr, for sizeof(T) == 1, and N > 1 Date: Sun, 30 Aug 2020 13:09:17 +0000 [thread overview] Message-ID: <bug-96851-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96851 Bug ID: 96851 Summary: operator< on std::array<T, N> does not work in constexpr, for sizeof(T) == 1, and N > 1 Product: gcc Version: 10.1.0 URL: https://gcc.godbolt.org/z/vjvYE5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: milasudril at gmail dot com Target Milestone: --- It appears that `operator<` on `std::array<T, N>` does not work in constexpr context, for `sizeof(T) == 1`, and `N > 1`. I tried different `T`and `N` combinations, and it appears that these work. MWE: #include <array> #include <cstddef> #include <cstdint> template<class T, size_t N> constexpr bool test(std::array<T, N> const& a, std::array<T, N> const& b) { return a < b; } using Type = int8_t; constexpr auto Count = 2; // Below does not compile constexpr auto value = test(std::array<Type, Count>{}, std::array<Type, Count>{}); The problem exists in gcc 10.1 and trunk. /opt/compiler-explorer/gcc-trunk-20200830/include/c++/11.0.0/array:262:32: error: '__builtin_memcmp(((std::array<signed char, 2>::const_pointer)(&<anonymous>.std::array<signed char, 2>::_M_elems)), ((std::array<signed char, 2>::const_pointer)(&<anonymous>.std::array<signed char, 2>::_M_elems)), 2)' is not a constant expression 262 | return __builtin_memcmp(__a.data(), __b.data(), _Nm) <=> 0; Godbolt url: https://gcc.godbolt.org/z/vjvYE5
next reply other threads:[~2020-08-30 13:09 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-30 13:09 milasudril at gmail dot com [this message] 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 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@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).