https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109976
Bug ID: 109976 Summary: error: is not a constant expression in std::equal() with _GLIBCXX_DEBUG Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: ed at catmur dot uk Target Milestone: --- #define _GLIBCXX_DEBUG #include <algorithm> #include <string> constexpr bool f(std::string const& l, std::string const& r) { return std::equal(l.data(), l.data() + l.size(), r.data(), r.data() + r.size()); } constexpr bool b = f("aa", "aa"); In file included from c++/14.0.0/debug/stl_iterator.h:32, from c++/14.0.0/bits/stl_iterator.h:3004, from c++/14.0.0/bits/stl_algobase.h:67, from c++/14.0.0/algorithm:60, from <source>:2: <source>:7:21: in 'constexpr' expansion of 'f(std::__cxx11::basic_string<char>(((const char*)"aa"), std::allocator<char>()), std::__cxx11::basic_string<char>(((const char*)"aa"), std::allocator<char>()))' <source>:5:22: in 'constexpr' expansion of 'std::equal<const char*, const char*>((& l)->std::__cxx11::basic_string<char>::data(), ((& l)->std::__cxx11::basic_string<char>::data() + ((sizetype)(& l)->std::__cxx11::basic_string<char>::size())), (& r)->std::__cxx11::basic_string<char>::data(), ((& r)->std::__cxx11::basic_string<char>::data() + ((sizetype)(& r)->std::__cxx11::basic_string<char>::size())))' c++/14.0.0/bits/stl_algobase.h:1679:7: in 'constexpr' expansion of '__gnu_debug::__valid_range<const char*>(__first1, __last1)' c++/14.0.0/debug/helper_functions.h:257:31: in 'constexpr' expansion of '__gnu_debug::__valid_range_aux<const char*>(__first, __last, (_Integral(), _Integral()))' c++/14.0.0/debug/helper_functions.h:189:31: in 'constexpr' expansion of '__gnu_debug::__valid_range_aux<const char*>(__first, __last, (std::__iterator_category<const char*>(__first), std::iterator_traits<const char*>::iterator_category()))' c++/14.0.0/debug/helper_functions.h:176:19: in 'constexpr' expansion of '__gnu_debug::__valid_range_aux<const char*>(__first, __last, (std::input_iterator_tag(), std::input_iterator_tag()))' c++/14.0.0/debug/helper_functions.h:136:20: error: '(((const char*)(&<anonymous>.std::__cxx11::basic_string<char>::<anonymous>.std::__cxx11::basic_string<char>::<unnamed union>::_M_local_buf)) == 0)' is not a constant expression 136 | { return __ptr == 0; } | ~~~~~~^~~~ This appears to be caused by bug 109975, but I'm filing separately since it may be possible to fix in library. The code is accepted if _GLIBCXX_DEBUG is not defined, since __gnu_debug::__valid_range is not checked.