https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77303
Bug ID: 77303 Summary: std::max_element not constexpr with -D_GLIBCXX_DEBUG Product: gcc Version: 6.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: lukibartl at gmail dot com Target Milestone: --- Created attachment 39476 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39476&action=edit The preprocessed file When compiling with -D_GLIBCXX_DEBUG, std::max_element is not constexpr: Code: #include <algorithm> int main() { constexpr size_t max = std::max({1, 2, 3}); return max; } Compiled with: g++ -v -save-temps -std=c++14 -D_GLIBCXX_DEBUG gcc_error.cpp Output: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/6.1.1/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 6.1.1 20160621 (Red Hat 6.1.1-3) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++14' '-D' '_GLIBCXX_DEBUG' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/6.1.1/cc1plus -E -quiet -v -D_GNU_SOURCE -D _GLIBCXX_DEBUG gcc_error.cpp -mtune=generic -march=x86-64 -std=c++14 -fpch-preprocess -o gcc_error.ii ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/6.1.1/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1 /usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/x86_64-redhat-linux /usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/backward /usr/lib/gcc/x86_64-redhat-linux/6.1.1/include /usr/local/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++14' '-D' '_GLIBCXX_DEBUG' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/6.1.1/cc1plus -fpreprocessed gcc_error.ii -quiet -dumpbase gcc_error.cpp -mtune=generic -march=x86-64 -auxbase gcc_error -std=c++14 -version -o gcc_error.s GNU C++14 (GCC) version 6.1.1 20160621 (Red Hat 6.1.1-3) (x86_64-redhat-linux) compiled by GNU C version 6.1.1 20160621 (Red Hat 6.1.1-3), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.2, isl version 0.14 or 0.13 warning: GMP header version 6.1.0 differs from library version 6.1.1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++14 (GCC) version 6.1.1 20160621 (Red Hat 6.1.1-3) (x86_64-redhat-linux) compiled by GNU C version 6.1.1 20160621 (Red Hat 6.1.1-3), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.2, isl version 0.14 or 0.13 warning: GMP header version 6.1.0 differs from library version 6.1.1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 8e1af9556445b8cc2090cc3ce62d071f In file included from /usr/include/c++/6.1.1/algorithm:62:0, from gcc_error.cpp:1: /usr/include/c++/6.1.1/bits/stl_algo.h: In function 'int main()': gcc_error.cpp:4:36: in constexpr expansion of 'std::max<int>(std::initializer_list<int>{((const int*)(& ._65)), 3u})' /usr/include/c++/6.1.1/bits/stl_algo.h:3460:31: error: 'constexpr _FIter std::max_element(_FIter, _FIter) [with _FIter = const int*]' called in a constant expression { return *std::max_element(__l.begin(), __l.end()); } ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/6.1.1/algorithm:62:0, from gcc_error.cpp:1: /usr/include/c++/6.1.1/bits/stl_algo.h:5539:5: note: 'constexpr _FIter std::max_element(_FIter, _FIter) [with _FIter = const int*]' is not usable as a constexpr function because: max_element(_ForwardIterator __first, _ForwardIterator __last) ^~~~~~~~~~~ /usr/include/c++/6.1.1/bits/stl_algo.h:5545:45: error: call to non-constexpr function 'bool __gnu_debug::__valid_range(const _InputIterator&, const _InputIterator&) [with _InputIterator = const int*]' __glibcxx_requires_valid_range(__first, __last); ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~