https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117966

            Bug ID: 117966
           Summary: [12/13/14/15 regression] constexpr std::span
                    construction fails to compile with D_GLIBCXX_DEBUG
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnu.ojxq8 at dralias dot com
  Target Milestone: ---

GCC-11 is fine, but any later version fails when running

g++ /tmp/a.cpp -std=c++20 -D_GLIBCXX_DEBUG -o /tmp/a

The file is:

#include <array>
#include <span>
struct A {
    constexpr A(std::span<const unsigned char>) {}
};
constexpr A val{std::array<unsigned char, 2>{0x11, 0x22}};


An error message may look like:

<source>:6:22:   in 'constexpr' expansion of 'std::span<const unsigned
char>(std::array<unsigned char, 2>{std::__array_traits<unsigned char,
2>::_Type{17, 34}})'
/opt/compiler-explorer/gcc-trunk-20241209/include/c++/15.0.0/span:207:57:   in
'constexpr' expansion of '((std::span<const unsigned
char>*)this)->std::span<const unsigned char>::span<const unsigned char*>((&
__arr)->std::array<unsigned char, 2>::data(), 2)'
/opt/compiler-explorer/gcc-trunk-20241209/include/c++/15.0.0/span:170:11:
error: '__builtin_expect(((long int)(! __gnu_debug::__valid_range<const
unsigned char*>(__first, (__first + ((sizetype)__count))))), 0)' is not a
constant expression
  170 |           __glibcxx_requires_valid_range(__first, __first + __count);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 1

Reply via email to