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?
commit c47326afadb0c330c19b872d5969d2f656499d0a
Author: Jonathan Wakely <jwak...@redhat.com>
Date: Thu Sep 26 15:44:04 2019 +0100
Make debug mode checks work in C++20 constexpr algorithms
* include/debug/formatter.h (__check_singular): Add
_GLIBCXX20_CONSTEXPR.
* include/debug/functions.h (__check_singular_aux, __check_singular)
(__check_valid_range, __foreign_iterator_aux4, __foreign_iterator_aux3)
(__foreign_iterator_aux2, __foreign_iterator_aux, __foreign_iterator)
(__check_sorted_aux, __check_sorted, __check_sorted_set_aux)
__check_sorted_set, __check_partitioned_lower)
(__check_partitioned_upper, _Irreflexive_checker::_S_is_valid)
(_Irreflexive_checker::_S_is_valid_pred, __is_reflexive)
(__is_reflexive_pred): Likewise.
* include/debug/helper_functions.h (__get_distance, __valid_range_aux)
(__valid_range, __can_advance, __base, __unsafe): Likewise.
* include/debug/safe_iterator.h (__valid_range, __can_advance)
(__base, __unsafe): Likewise.
* include/debug/safe_local_iterator.h (__valid_range, __can_advance)
(__unsafe): Likewise.
diff --git a/libstdc++-v3/include/debug/formatter.h b/libstdc++-v3/include/debug/formatter.h
index 220379994c0..6f17ab4627c 100644
--- a/libstdc++-v3/include/debug/formatter.h
+++ b/libstdc++-v3/include/debug/formatter.h
@@ -72,7 +72,7 @@ namespace __gnu_debug
using std::type_info;
template<typename _Iterator>
- bool __check_singular(const _Iterator&);
+ _GLIBCXX20_CONSTEXPR bool __check_singular(const _Iterator&);
class _Safe_sequence_base;
diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h
index f87838692c6..bbfbe15fefa 100644
--- a/libstdc++-v3/include/debug/functions.h
+++ b/libstdc++-v3/include/debug/functions.h
@@ -50,19 +50,19 @@ namespace __gnu_debug
struct _Is_contiguous_sequence : std::__false_type { };
// An arbitrary iterator pointer is not singular.
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_singular_aux(const void*) { return false; }
// We may have an iterator that derives from _Safe_iterator_base but isn't
// a _Safe_iterator.
template<typename _Iterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_singular(const _Iterator& __x)
{ return __check_singular_aux(std::__addressof(__x)); }
/** Non-NULL pointers are nonsingular. */
template<typename _Tp>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_singular(const _Tp* __ptr)
{ return __ptr == 0; }
@@ -71,7 +71,7 @@ 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,
@@ -85,7 +85,7 @@ namespace __gnu_debug
/* Handle the case where __other is a pointer to _Sequence::value_type. */
template<typename _Iterator, typename _Sequence, typename _Category>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
const typename _Sequence::value_type* __other)
@@ -107,7 +107,7 @@ namespace __gnu_debug
/* Fallback overload for when we can't tell, assume it is valid. */
template<typename _Iterator, typename _Sequence, typename _Category>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence, _Category>&, ...)
{ return true; }
@@ -115,7 +115,7 @@ namespace __gnu_debug
/* Handle sequences with contiguous storage */
template<typename _Iterator, typename _Sequence, typename _Category,
typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
const _InputIterator& __other, const _InputIterator& __other_end,
@@ -131,7 +131,7 @@ namespace __gnu_debug
/* Handle non-contiguous containers, assume it is valid. */
template<typename _Iterator, typename _Sequence, typename _Category,
typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence, _Category>&,
const _InputIterator&, const _InputIterator&,
@@ -141,7 +141,7 @@ namespace __gnu_debug
/** Handle debug iterators from the same type of container. */
template<typename _Iterator, typename _Sequence, typename _Category,
typename _OtherIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux2(
const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
const _Safe_iterator<_OtherIterator, _Sequence, _Category>& __other,
@@ -152,7 +152,7 @@ namespace __gnu_debug
template<typename _Iterator, typename _Sequence, typename _Category,
typename _OtherIterator, typename _OtherSequence,
typename _OtherCategory>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux2(
const _Safe_iterator<_Iterator, _Sequence, _Category>&,
const _Safe_iterator<_OtherIterator, _OtherSequence,
@@ -164,7 +164,7 @@ namespace __gnu_debug
/* Handle non-debug iterators. */
template<typename _Iterator, typename _Sequence, typename _Category,
typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux2(
const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
const _InputIterator& __other,
@@ -185,7 +185,7 @@ namespace __gnu_debug
/* Handle the case where we aren't really inserting a range after all */
template<typename _Iterator, typename _Sequence, typename _Category,
typename _Integral>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence, _Category>&,
_Integral, _Integral, std::__true_type)
@@ -194,7 +194,7 @@ namespace __gnu_debug
/* Handle all iterators. */
template<typename _Iterator, typename _Sequence, typename _Category,
typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
_InputIterator __other, _InputIterator __other_end,
@@ -207,7 +207,7 @@ namespace __gnu_debug
template<typename _Iterator, typename _Sequence, typename _Category,
typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__foreign_iterator(
const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
_InputIterator __other, _InputIterator __other_end)
@@ -219,7 +219,7 @@ namespace __gnu_debug
// Can't check if an input iterator sequence is sorted, because we
// can't step through the sequence.
template<typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_aux(const _InputIterator&, const _InputIterator&,
std::input_iterator_tag)
{ return true; }
@@ -227,7 +227,7 @@ namespace __gnu_debug
// Can verify if a forward iterator sequence is in fact sorted using
// std::__is_sorted
template<typename _ForwardIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
std::forward_iterator_tag)
{
@@ -245,7 +245,7 @@ namespace __gnu_debug
// Can't check if an input iterator sequence is sorted, because we can't step
// through the sequence.
template<typename _InputIterator, typename _Predicate>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_aux(const _InputIterator&, const _InputIterator&,
_Predicate, std::input_iterator_tag)
{ return true; }
@@ -253,7 +253,7 @@ namespace __gnu_debug
// Can verify if a forward iterator sequence is in fact sorted using
// std::__is_sorted
template<typename _ForwardIterator, typename _Predicate>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
_Predicate __pred, std::forward_iterator_tag)
{
@@ -270,7 +270,7 @@ namespace __gnu_debug
// Determine if a sequence is sorted.
template<typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted(const _InputIterator& __first, const _InputIterator& __last)
{
// Verify that the < operator for elements in the sequence is a
@@ -282,7 +282,7 @@ namespace __gnu_debug
}
template<typename _InputIterator, typename _Predicate>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted(const _InputIterator& __first, const _InputIterator& __last,
_Predicate __pred)
{
@@ -295,28 +295,28 @@ namespace __gnu_debug
}
template<typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_set_aux(const _InputIterator& __first,
const _InputIterator& __last,
std::__true_type)
{ return __check_sorted(__first, __last); }
template<typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_set_aux(const _InputIterator&,
const _InputIterator&,
std::__false_type)
{ return true; }
template<typename _InputIterator, typename _Predicate>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_set_aux(const _InputIterator& __first,
const _InputIterator& __last,
_Predicate __pred, std::__true_type)
{ return __check_sorted(__first, __last, __pred); }
template<typename _InputIterator, typename _Predicate>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_set_aux(const _InputIterator&,
const _InputIterator&, _Predicate,
std::__false_type)
@@ -324,7 +324,7 @@ namespace __gnu_debug
// ... special variant used in std::merge, std::includes, std::set_*.
template<typename _InputIterator1, typename _InputIterator2>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_set(const _InputIterator1& __first,
const _InputIterator1& __last,
const _InputIterator2&)
@@ -341,7 +341,7 @@ namespace __gnu_debug
template<typename _InputIterator1, typename _InputIterator2,
typename _Predicate>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_sorted_set(const _InputIterator1& __first,
const _InputIterator1& __last,
const _InputIterator2&, _Predicate __pred)
@@ -360,7 +360,7 @@ namespace __gnu_debug
// 270. Binary search requirements overly strict
// Determine if a sequence is partitioned w.r.t. this element.
template<typename _ForwardIterator, typename _Tp>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_partitioned_lower(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value)
{
@@ -376,7 +376,7 @@ namespace __gnu_debug
}
template<typename _ForwardIterator, typename _Tp>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_partitioned_upper(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value)
{
@@ -393,7 +393,7 @@ namespace __gnu_debug
// Determine if a sequence is partitioned w.r.t. this element.
template<typename _ForwardIterator, typename _Tp, typename _Pred>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_partitioned_lower(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value,
_Pred __pred)
@@ -410,7 +410,7 @@ namespace __gnu_debug
}
template<typename _ForwardIterator, typename _Tp, typename _Pred>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__check_partitioned_upper(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value,
_Pred __pred)
@@ -435,36 +435,36 @@ namespace __gnu_debug
template<typename _It,
typename = decltype(__deref<_It>() < __deref<_It>())>
- static bool
+ _GLIBCXX20_CONSTEXPR static bool
_S_is_valid(_It __it)
{ return !(*__it < *__it); }
// Fallback method if operator doesn't exist.
template<typename... _Args>
- static bool
+ _GLIBCXX20_CONSTEXPR static bool
_S_is_valid(_Args...)
{ return true; }
template<typename _It, typename _Pred, typename
= decltype(std::declval<_Pred>()(__deref<_It>(), __deref<_It>()))>
- static bool
+ _GLIBCXX20_CONSTEXPR static bool
_S_is_valid_pred(_It __it, _Pred __pred)
{ return !__pred(*__it, *__it); }
// Fallback method if predicate can't be invoked.
template<typename... _Args>
- static bool
+ _GLIBCXX20_CONSTEXPR static bool
_S_is_valid_pred(_Args...)
{ return true; }
};
template<typename _Iterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__is_irreflexive(_Iterator __it)
{ return _Irreflexive_checker::_S_is_valid(__it); }
template<typename _Iterator, typename _Pred>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__is_irreflexive_pred(_Iterator __it, _Pred __pred)
{ return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }
#endif
diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h
index b7aeafef12a..a8686701454 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -87,13 +87,13 @@ namespace __gnu_debug
* precision.
*/
template<typename _Iterator>
- inline typename _Distance_traits<_Iterator>::__type
+ _GLIBCXX20_CONSTEXPR inline typename _Distance_traits<_Iterator>::__type
__get_distance(_Iterator __lhs, _Iterator __rhs,
std::random_access_iterator_tag)
{ return std::make_pair(__rhs - __lhs, __dp_exact); }
template<typename _Iterator>
- inline typename _Distance_traits<_Iterator>::__type
+ _GLIBCXX20_CONSTEXPR inline typename _Distance_traits<_Iterator>::__type
__get_distance(_Iterator __lhs, _Iterator __rhs,
std::input_iterator_tag)
{
@@ -104,7 +104,7 @@ namespace __gnu_debug
}
template<typename _Iterator>
- inline typename _Distance_traits<_Iterator>::__type
+ _GLIBCXX20_CONSTEXPR inline typename _Distance_traits<_Iterator>::__type
__get_distance(_Iterator __lhs, _Iterator __rhs)
{ return __get_distance(__lhs, __rhs, std::__iterator_category(__lhs)); }
@@ -113,7 +113,7 @@ namespace __gnu_debug
* iterators.
*/
template<typename _Integral>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range_aux(_Integral, _Integral,
typename _Distance_traits<_Integral>::__type& __dist,
std::__true_type)
@@ -126,7 +126,7 @@ namespace __gnu_debug
* to see if we can check the range ahead of time.
*/
template<typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range_aux(_InputIterator __first, _InputIterator __last,
typename _Distance_traits<_InputIterator>::__type& __dist,
std::__false_type)
@@ -155,7 +155,7 @@ namespace __gnu_debug
* otherwise.
*/
template<typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range(_InputIterator __first, _InputIterator __last,
typename _Distance_traits<_InputIterator>::__type& __dist)
{
@@ -164,21 +164,21 @@ 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&);
#if __cplusplus >= 201103L
- template<typename _Iterator,typename _Sequence>
- bool
+ template<typename _Iterator, typename _Sequence>
+ _GLIBCXX20_CONSTEXPR bool
__valid_range(const _Safe_local_iterator<_Iterator, _Sequence>&,
const _Safe_local_iterator<_Iterator, _Sequence>&,
typename _Distance_traits<_Iterator>::__type&);
#endif
template<typename _InputIterator>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range(_InputIterator __first, _InputIterator __last)
{
typename _Distance_traits<_InputIterator>::__type __dist;
@@ -186,26 +186,26 @@ 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>&);
#if __cplusplus >= 201103L
template<typename _Iterator, typename _Sequence>
- bool
+ _GLIBCXX20_CONSTEXPR bool
__valid_range(const _Safe_local_iterator<_Iterator, _Sequence>&,
const _Safe_local_iterator<_Iterator, _Sequence>&);
#endif
// Fallback method, always ok.
template<typename _InputIterator, typename _Size>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__can_advance(_InputIterator, _Size)
{ return true; }
template<typename _Iterator, typename _Sequence, typename _Category,
typename _Size>
- bool
+ _GLIBCXX20_CONSTEXPR bool
__can_advance(const _Safe_iterator<_Iterator, _Sequence, _Category>&,
_Size);
@@ -216,7 +216,7 @@ namespace __gnu_debug
* thanks to the < operator.
*/
template<typename _Iterator>
- inline _Iterator
+ _GLIBCXX20_CONSTEXPR inline _Iterator
__base(_Iterator __it)
{ return __it; }
@@ -228,7 +228,7 @@ namespace __gnu_debug
/* Remove debug mode safe iterator layer, if any. */
template<typename _Iterator>
- inline _Iterator
+ _GLIBCXX20_CONSTEXPR inline _Iterator
__unsafe(_Iterator __it)
{ return __it; }
}
diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h
index 6700eafca0b..0387367a08f 100644
--- a/libstdc++-v3/include/debug/safe_iterator.h
+++ b/libstdc++-v3/include/debug/safe_iterator.h
@@ -905,7 +905,7 @@ namespace __gnu_debug
/** Safe iterators know how to check if they form a valid range. */
template<typename _Iterator, typename _Sequence, typename _Category>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range(const _Safe_iterator<_Iterator, _Sequence,
_Category>& __first,
const _Safe_iterator<_Iterator, _Sequence,
@@ -914,7 +914,7 @@ namespace __gnu_debug
{ return __first._M_valid_range(__last, __dist); }
template<typename _Iterator, typename _Sequence, typename _Category>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range(const _Safe_iterator<_Iterator, _Sequence,
_Category>& __first,
const _Safe_iterator<_Iterator, _Sequence,
@@ -926,13 +926,13 @@ namespace __gnu_debug
template<typename _Iterator, typename _Sequence, typename _Category,
typename _Size>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__can_advance(const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
_Size __n)
{ return __it._M_can_advance(__n); }
template<typename _Iterator, typename _Sequence>
- _Iterator
+ _GLIBCXX20_CONSTEXPR _Iterator
__base(const _Safe_iterator<_Iterator, _Sequence,
std::random_access_iterator_tag>& __it)
{ return __it.base(); }
@@ -944,7 +944,7 @@ namespace __gnu_debug
#endif
template<typename _Iterator, typename _Sequence>
- inline _Iterator
+ _GLIBCXX20_CONSTEXPR inline _Iterator
__unsafe(const _Safe_iterator<_Iterator, _Sequence>& __it)
{ return __it.base(); }
diff --git a/libstdc++-v3/include/debug/safe_local_iterator.h b/libstdc++-v3/include/debug/safe_local_iterator.h
index 40919126c9f..299487241bc 100644
--- a/libstdc++-v3/include/debug/safe_local_iterator.h
+++ b/libstdc++-v3/include/debug/safe_local_iterator.h
@@ -403,14 +403,14 @@ namespace __gnu_debug
/** Safe local iterators know how to check if they form a valid range. */
template<typename _Iterator, typename _Sequence>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range(const _Safe_local_iterator<_Iterator, _Sequence>& __first,
const _Safe_local_iterator<_Iterator, _Sequence>& __last,
typename _Distance_traits<_Iterator>::__type& __dist_info)
{ return __first._M_valid_range(__last, __dist_info); }
template<typename _Iterator, typename _Sequence>
- inline bool
+ _GLIBCXX20_CONSTEXPR inline bool
__valid_range(const _Safe_local_iterator<_Iterator, _Sequence>& __first,
const _Safe_local_iterator<_Iterator, _Sequence>& __last)
{
@@ -425,7 +425,7 @@ namespace __gnu_debug
#endif
template<typename _Iterator, typename _Sequence>
- inline _Iterator
+ _GLIBCXX20_CONSTEXPR inline _Iterator
__unsafe(const _Safe_local_iterator<_Iterator, _Sequence>& __it)
{ return __it.base(); }