https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109517
Bug ID: 109517 Summary: Failure to compile constexpr std::copy with -D_GLIBCXX_DEBUG Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: terra at gnome dot org Target Milestone: --- Created attachment 54861 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54861&action=edit Preprocessed source code The following program fails to compile with -std=gnu++20 -D_GLIBCXX_DEBUG due to something in the library not being constexpr. It compiles just fine without -D_GLIBCXX_DEBUG. FWIW, clang 15 sees no problem (without -D...) other than "farm" being unused. ------------------------------------------------------------------ #include <array> #include <algorithm> #include <initializer_list> class wrapper : public std::array<const char *, 3> { public: constexpr wrapper(std::initializer_list<const char *> list) { std::copy(list.begin(), list.end(), this->begin()); } }; constexpr wrapper farm = { "moo", "oink", "baa" }; ------------------------------------------------------------------ /usr/local/products/gcc/12.1.0/bin/g++ -v -std=gnu++20 -D_GLIBCXX_DEBUG -c uuu.C Using built-in specs. COLLECT_GCC=/usr/local/products/gcc/12.1.0/bin/g++ COLLECT_LTO_WRAPPER=/usr/local/products/gcc/12.1.0/lib/gcc/x86_64-suse-linux/12.1.0/lto-wrapper Target: x86_64-suse-linux Configured with: ../../gcc-12.1.0/configure --enable-languages=c,c++,fortran --enable-targets=x86_64-suse-linux,i686-suse-linux --prefix=/usr/local/products/gcc/12.1.0 --with-gnu-as --with-as=/usr/local/products/gcc/binutils-2.38/bin/as --with-ld=/usr/local/products/gcc/binutils-2.38/bin/ld.gold --enable-link-mutex --enable-gnu-indirect-functions --enable-linux-futex --enable-threads=posix --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new x86_64-suse-linux Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.1.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-std=gnu++20' '-D' '_GLIBCXX_DEBUG' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-' /usr/local/products/gcc/12.1.0/lib/gcc/x86_64-suse-linux/12.1.0/cc1plus -quiet -v -D_GNU_SOURCE -D _GLIBCXX_DEBUG uuu.C -quiet -dumpdir a- -dumpbase uuu.C -dumpbase-ext .C -mtune=generic -march=x86-64 -std=gnu++20 -version -o /tmp/cc5WkAgd.s GNU C++20 (GCC) version 12.1.0 (x86_64-suse-linux) compiled by GNU C version 12.1.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/products/gcc/12.1.0/lib64/gcc/x86_64-suse-linux/12.1.0/../../../../x86_64-suse-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/products/gcc/12.1.0/lib64/gcc/x86_64-suse-linux/12.1.0/../../../../include/c++/12.1.0 /usr/local/products/gcc/12.1.0/lib64/gcc/x86_64-suse-linux/12.1.0/../../../../include/c++/12.1.0/x86_64-suse-linux /usr/local/products/gcc/12.1.0/lib64/gcc/x86_64-suse-linux/12.1.0/../../../../include/c++/12.1.0/backward /usr/local/products/gcc/12.1.0/lib64/gcc/x86_64-suse-linux/12.1.0/include /usr/local/include /usr/local/products/gcc/12.1.0/include /usr/local/products/gcc/12.1.0/lib64/gcc/x86_64-suse-linux/12.1.0/include-fixed /usr/include End of search list. GNU C++20 (GCC) version 12.1.0 (x86_64-suse-linux) compiled by GNU C version 12.1.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 9e0c9110c7d4f6deb64439dc23f707eb In file included from /usr/local/products/gcc/12.1.0/include/c++/12.1.0/debug/stl_iterator.h:32, from /usr/local/products/gcc/12.1.0/include/c++/12.1.0/bits/stl_iterator.h:2559, from /usr/local/products/gcc/12.1.0/include/c++/12.1.0/bits/stl_algobase.h:67, from /usr/local/products/gcc/12.1.0/include/c++/12.1.0/array:43, from uuu.C:1: uuu.C:12:49: in ‘constexpr’ expansion of ‘wrapper(std::initializer_list<const char*>{((const char* const*)(& const char* const [3]{((const char*)"moo"), ((const char*)"oink"), ((const char*)"baa")})), 3})’ uuu.C:8:14: in ‘constexpr’ expansion of ‘std::copy<const char* const*, const char**>(list.std::initializer_list<const char*>::begin(), list.std::initializer_list<const char*>::end(), ((wrapper*)this)->wrapper::<anonymous>.std::array<const char*, 3>::begin())’ /usr/local/products/gcc/12.1.0/include/c++/12.1.0/bits/stl_algobase.h:617:7: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range<const char* const*>(__first, __last, __dist)’ /usr/local/products/gcc/12.1.0/include/c++/12.1.0/debug/helper_functions.h:234:31: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const char* const*>(__first, __last, (* & __dist), (_Integral(), _Integral()))’ /usr/local/products/gcc/12.1.0/include/c++/12.1.0/debug/helper_functions.h:200:29: in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const char* const*>(__first, __last, (std::input_iterator_tag(), std::input_iterator_tag()))’ /usr/local/products/gcc/12.1.0/include/c++/12.1.0/debug/helper_functions.h:136:20: error: ‘(((const char* const*)(&<anonymous>)) == 0)’ is not a constant expression 136 | { return __ptr == 0; } | ~~~~~~^~~~