[gcc r15-11254] libstdc++: Backport constexpr support for debug mode helpers [PR119163]
Jonathan Wakely
redi@gcc.gnu.org
Thu Jun 4 14:45:29 GMT 2026
https://gcc.gnu.org/g:6e0376b42d4c6eff348a151b0f66453c5a5d8f00
commit r15-11254-g6e0376b42d4c6eff348a151b0f66453c5a5d8f00
Author: François Dumont <frs.dumont@gmail.com>
Date: Mon Sep 22 18:58:52 2025 +0200
libstdc++: Backport constexpr support for debug mode helpers [PR119163]
This is a partial backport of r16-5845-g8a2e6590cc4a2f to fix a test
failure with -D_GLIBCXX_DEBUG:
FAIL: 20_util/specialized_algorithms/uninitialized_copy/constexpr.cc -std=gnu++26 (test for excess errors)
libstdc++-v3/ChangeLog:
PR libstdc++/119163
* include/debug/functions.h (__check_valid_range): Add C++20 constexpr.
* include/debug/helper_functions.h (__valid_range): Likewise.
* include/debug/safe_iterator.h (__valid_range): Likewise.
Diff:
---
libstdc++-v3/include/debug/functions.h | 10 +++++++---
libstdc++-v3/include/debug/helper_functions.h | 4 ++--
libstdc++-v3/include/debug/safe_iterator.h | 12 +++++++++++-
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h
index c5f5582b0050..4e6fdae71935 100644
--- a/libstdc++-v3/include/debug/functions.h
+++ b/libstdc++-v3/include/debug/functions.h
@@ -53,15 +53,19 @@ namespace __gnu_debug
* assertion statement because, e.g., we are in a constructor.
*/
template<typename _InputIterator>
- inline _InputIterator
+ _GLIBCXX20_CONSTEXPR inline _InputIterator
__check_valid_range(const _InputIterator& __first,
const _InputIterator& __last,
const char* __file,
unsigned int __line,
const char* __function)
{
- __glibcxx_check_valid_range_at(__first, __last,
- __file, __line, __function);
+ if (!std::__is_constant_evaluated())
+ {
+ __glibcxx_check_valid_range_at(__first, __last,
+ __file, __line, __function);
+ }
+
return __first;
}
diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h
index 9395892b537c..b9771034bf34 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -249,7 +249,7 @@ namespace __gnu_debug
}
template<typename _Iterator, typename _Sequence, typename _Category>
- bool
+ _GLIBCXX20_CONSTEXPR bool
__valid_range(const _Safe_iterator<_Iterator, _Sequence, _Category>&,
const _Safe_iterator<_Iterator, _Sequence, _Category>&,
typename _Distance_traits<_Iterator>::__type&);
@@ -272,7 +272,7 @@ namespace __gnu_debug
}
template<typename _Iterator, typename _Sequence, typename _Category>
- bool
+ _GLIBCXX20_CONSTEXPR bool
__valid_range(const _Safe_iterator<_Iterator, _Sequence, _Category>&,
const _Safe_iterator<_Iterator, _Sequence, _Category>&);
diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h
index 7c563381d0bf..9c5f360414bf 100644
--- a/libstdc++-v3/include/debug/safe_iterator.h
+++ b/libstdc++-v3/include/debug/safe_iterator.h
@@ -1108,21 +1108,31 @@ namespace __gnu_debug
/** Safe iterators know how to check if they form a valid range. */
template<typename _Iterator, typename _Sequence, typename _Category>
+ _GLIBCXX20_CONSTEXPR
inline bool
__valid_range(const _Safe_iterator<_Iterator, _Sequence,
_Category>& __first,
const _Safe_iterator<_Iterator, _Sequence,
_Category>& __last,
typename _Distance_traits<_Iterator>::__type& __dist)
- { return __first._M_valid_range(__last, __dist); }
+ {
+ if (std::__is_constant_evaluated())
+ return true;
+
+ return __first._M_valid_range(__last, __dist);
+ }
template<typename _Iterator, typename _Sequence, typename _Category>
+ _GLIBCXX20_CONSTEXPR
inline bool
__valid_range(const _Safe_iterator<_Iterator, _Sequence,
_Category>& __first,
const _Safe_iterator<_Iterator, _Sequence,
_Category>& __last)
{
+ if (std::__is_constant_evaluated())
+ return true;
+
typename _Distance_traits<_Iterator>::__type __dist;
return __first._M_valid_range(__last, __dist);
}
More information about the Libstdc++-cvs
mailing list