Here is what I just commited. I try to use the asm trick in the _GLIBCXX_DEBUG_VERIFY_COND_AT but didn't notice any enhancement. So for now I kept my solution to just have a non-constexpr call compiler error. I fix my patch to use __builtin_is_constant_evaluated rather than std::is_constant_evaluated in __valid_range.     * include/bits/stl_algobase.h (__memmove): Return _Tp*.     (__memmove): Loop as long as __n is not 0.     (__copy_move<>::__copy_m): Likewise.     (__copy_move_backward<>::__copy_move_b): Likewise.     * testsuite/25_algorithms/copy/constexpr.cc: Add check on copied values.     * testsuite/25_algorithms/copy_backward/constexpr.cc: Likewise.     * testsuite/25_algorithms/copy/constexpr_neg.cc: New.     * testsuite/25_algorithms/copy_backward/constexpr.cc: New.     * include/debug/forward_list (_Sequence_traits<__debug::forward_list<>>::_S_size): Returns __dp_sign     distance when not empty.     * include/debug/list     (_Sequence_traits<__debug::list<>>::_S_size): Likewise.     * include/debug/helper_functions.h (__dp_sign_max_size): New     _Distance_precision enum entry.     * include/debug/safe_iterator.h     (__copy_move_a(_II, _II, const _Safe_iterator<>&)): Check for output     iterator _M_can_advance as soon as input range distance precision is     strictly higher than __dp_size.     (__copy_move_a(const _Safe_iterator<>&, const _Safe_iterator<>&,     const _Safe_iterator<>&)): Likewise.     (__copy_move_backward_a(_II, _II, const _Safe_iterator<>&)): Likewise.     (__copy_move_backward_a(const _Safe_iterator<>&,     const _Safe_iterator<>&, const _Safe_iterator<>&)): Likewise.     (__equal_aux(_II, _II, const _Safe_iterator<>&)): Likewise.     (__equal_aux(const _Safe_iterator<>&,     const _Safe_iterator<>&, const _Safe_iterator<>&)): Likewise. François On 9/27/19 6:45 PM, Jonathan Wakely wrote: > On 27/09/19 18:24 +0200, François Dumont wrote: >> On 9/27/19 2:11 PM, Jonathan Wakely wrote: >>> On 19/09/19 22:27 +0200, François Dumont wrote: >>>> Hi >>>> >>>>     I start working on making recently added constexpr tests to >>>> work in Debug mode. >>> >>> The attached patch seems to be necessary for that, right? >>> >>> >> On my side I had done this, almost the same. >> >> For the moment there is a FIXME in macros.h to find out how to >> generate a nice compilation error when the condition is not meant. >> >> static_assert can't be called in this context, too bad. >> >> I also try to define a function with a >> __attribute__((__error__("because"))) attribute. But when I make it >> constexpr gcc complains about missing definition. When I provide a >> definition gcc complains that this attribute must be on a >> declaration. And when I split declaration and definition gcc does not >> produce the expected compilation error. > > Yes, I've tried similar things without success. > >> Unless you have the solution I consider that we need help from the >> front-end. >> >> For the moment if Debug mode finds a problem it will be reported as >> _M_error function not being constexpr ! > > A reasonable workaround is to do: > > #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED >  if (__builtin_is_constant_evaluated()) >    asm("Debug Mode assertion failed"); >  else > #endif >  if (!(Cond)) >    __gnu_debug::_Error_formatter::... > > The builtin is available even for C++98, whereas > std::is_constant_evaluated() is only available for C++20. > > This produces errors that include lines like: > > asm.cc:12:17:   in ‘constexpr’ expansion of ‘f(-1)’ > asm.cc:4:7: error: inline assembly is not a constant expression >    4 |       asm("debug mode assertion failed"); >      |       ^~~ > asm.cc:8:3: note: in expansion of macro ‘CHECK’ >    8 |   _GLIBCXX_ASSERT(i > 0); >      |   ^~~~~ > asm.cc:4:7: note: only unevaluated inline assembly is allowed in a > ‘constexpr’ function in C++2a >    4 |       asm("debug mode assertion failed"); >      |       ^~~ > asm.cc:8:3: note: in expansion of macro ‘CHECK’ >    8 |   CHECK(i > 0); >      |   ^~~~~ > > It's not ideal, but it does show the failed condition and the text > "debug mode assertion failed" (or whatever message you choose to use > there). > > >