public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/96851] New: operator< on std::array<T, N> does not work in constexpr, for sizeof(T) == 1, and N > 1
@ 2020-08-30 13:09 milasudril at gmail dot com
  2020-08-30 13:15 ` [Bug libstdc++/96851] " milasudril at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: milasudril at gmail dot com @ 2020-08-30 13:09 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-07-12 11:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-30 13:09 [Bug libstdc++/96851] New: operator< on std::array<T, N> does not work in constexpr, for sizeof(T) == 1, and N > 1 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
2020-09-02 15:46 ` redi at gcc dot gnu.org
2021-07-12 11:14 ` redi at gcc dot gnu.org

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).