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

Reply via email to