https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111250
Bug ID: 111250 Summary: __glibcxx_requires_subscript assertions are not checked during constant evaluation Product: gcc Version: 13.2.1 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- This means the following example from Peter Dimov only fails with -D_GLIBCXX_ASSERTIONS or -D_GLIBCXX_DEBUG: #include <vector> constexpr bool f() { std::vector<int> v{ 1, 2, 3 }; return &v[3] == &v.front(); } constexpr bool b = f(); The __glibcxx_assert macro expands to a __glibcxx_constexpr_assert check that is always checked during constant evaluation, even without -D_GLIBCXX_ASSERTIONS. However, the __glibcxx_requires_subscript macro does not use __glibcxx_assert and just expands to nothing. See <debug/assertions.h>: #ifndef _GLIBCXX_ASSERTIONS # define __glibcxx_requires_non_empty_range(_First,_Last) # define __glibcxx_requires_nonempty() # define __glibcxx_requires_subscript(_N) #else // Verify that [_First, _Last) forms a non-empty iterator range. # define __glibcxx_requires_non_empty_range(_First,_Last) \ __glibcxx_assert(_First != _Last) # define __glibcxx_requires_subscript(_N) \ __glibcxx_assert(_N < this->size()) // Verify that the container is nonempty # define __glibcxx_requires_nonempty() \ __glibcxx_assert(!this->empty()) #endif I think we should remove the #ifndef and just always expand those to __glibcxx_assert expressions. That will mean they're checked during constant evaluation.