]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: [_GLIBCXX_DEBUG][__cplusplus >= 201103L] Remove useless workaround
authorFrançois Dumont <frs.dumont@gmail.com>
Mon, 23 Feb 2026 17:58:00 +0000 (18:58 +0100)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Sat, 7 Mar 2026 21:04:19 +0000 (22:04 +0100)
Starting with C++11 we leverage on template parameter requirement to prevent
instantiation of methods taking iterators with invalid types.
So the _GLIBCXX_DEBUG mode do not need to check for potential ambiguity between
integer type and iterator type anymore.

libstdc++-v3/ChangeLog:

* include/debug/functions.h [__cplusplus >= 201103L]
(__foreign_iterator_aux): Remove.
(__foreign_iterator): Adapt to use __foreign_iterator_aux2.
* include/debug/helper_functions.h [__cplusplus >= 201103L]:
Remove include bits/cpp_type_traits.h.
(_Distance_traits<_Integral, std::__true_type>): Remove.
(__valid_range_aux(_Integral, _Integral, std::__true_type)):
Remove.
(__valid_range_aux(_Iterator, _Iterator, std::__false_type)): Remove.
(__valid_range_aux(_Integral, _Integral, _Distance_traits<_Integral>::__type&,
std::__true_type)): Remove.
(__valid_range_aux(_Iterator, _Iterator, _Distance_traits<_Iterator>::__type&,
std::__false_type)): Remove.
(__valid_range(_Iterator, _Iterator)): Adapt.
(__valid_range(_Iterator, _Iterator, _Distance_traits<_Iterator>::__type&)): Adapt.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/debug/functions.h
libstdc++-v3/include/debug/helper_functions.h

index 99a0c41758d7821e713531cc75e9991313d40239..d2acba34ef28df879d31ad3cbcee0d451ac54b59 100644 (file)
@@ -168,6 +168,7 @@ namespace __gnu_debug
       return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
     }
 
+#if __cplusplus < 201103L
   /* Handle the case where we aren't really inserting a range after all */
   template<typename _Iterator, typename _Sequence, typename _Category,
           typename _Integral>
@@ -185,12 +186,21 @@ namespace __gnu_debug
        const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
        _InputIterator __other, _InputIterator __other_end,
        std::__false_type)
+#else
+  template<typename _Iterator, typename _Sequence, typename _Category,
+          typename _InputIterator>
+    inline bool
+    __foreign_iterator(
+       const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
+       _InputIterator __other, _InputIterator __other_end)
+#endif
     {
       return _Insert_range_from_self_is_safe<_Sequence>::__value
        || __foreign_iterator_aux2(__it, std::__miter_base(__other),
                                   std::__miter_base(__other_end));
     }
 
+#if __cplusplus < 201103L
   template<typename _Iterator, typename _Sequence, typename _Category,
           typename _InputIterator>
     inline bool
@@ -201,6 +211,7 @@ namespace __gnu_debug
       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
       return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
     }
+#endif
 
   // Can't check if an input iterator sequence is sorted, because we
   // can't step through the sequence.
index 8ef2168465031ce1ef100c5eb4dd3b77afa78e57..0bd5a1cbdf45917fb3a6aaa5582703248ff7fd0c 100644 (file)
@@ -32,7 +32,9 @@
 #include <bits/move.h>                         // for __addressof
 #include <bits/stl_iterator_base_types.h>      // for iterator_traits,
                                                // categories and _Iter_base
-#include <bits/cpp_type_traits.h>              // for __is_integer
+#if __cplusplus < 201103L
+# include <bits/cpp_type_traits.h>             // for __is_integer
+#endif
 
 #include <bits/stl_pair.h>                     // for pair
 
@@ -58,8 +60,12 @@ namespace __gnu_debug
       __dp_exact               //< Can determine distance precisely
     };
 
+#if __cplusplus >= 201103L
+  template<typename _Iterator>
+#else
   template<typename _Iterator,
           typename = typename std::__is_integer<_Iterator>::__type>
+#endif
     struct _Distance_traits
     {
     private:
@@ -80,9 +86,11 @@ namespace __gnu_debug
       typedef std::pair<_DiffType, _Distance_precision> __type;
     };
 
+#if __cplusplus < 201103L
   template<typename _Integral>
     struct _Distance_traits<_Integral, std::__true_type>
     { typedef std::pair<std::ptrdiff_t, _Distance_precision> __type; };
+#endif
 
   /** Determine the distance between two iterators with some known
    *   precision.
@@ -141,18 +149,14 @@ namespace __gnu_debug
     __check_singular(_Tp* const& __ptr)
     { return __ptr == 0; }
 
-  /** We say that integral types for a valid range, and defer to other
-   *  routines to realize what to do with integral types instead of
-   *  iterators.
-  */
+#if __cplusplus < 201103L
+  // In case of integral type no assertions.
   template<typename _Integral>
-    _GLIBCXX_CONSTEXPR
     inline bool
     __valid_range_aux(_Integral, _Integral, std::__true_type)
     { return true; }
 
   template<typename _Integral>
-    _GLIBCXX20_CONSTEXPR
     inline bool
     __valid_range_aux(_Integral, _Integral,
                      typename _Distance_traits<_Integral>::__type& __dist,
@@ -161,6 +165,7 @@ namespace __gnu_debug
       __dist = std::make_pair(0, __dp_none);
       return true;
     }
+#endif
 
   template<typename _InputIterator>
     _GLIBCXX_CONSTEXPR
@@ -189,25 +194,37 @@ namespace __gnu_debug
        && __first <= __last;
     }
 
+#if __cplusplus >= 201103L
+  template<typename _InputIterator>
+    constexpr bool
+    __valid_range(_InputIterator __first, _InputIterator __last)
+#else
   /** We have iterators, so figure out what kind of iterators they are
    *  to see if we can check the range ahead of time.
   */
   template<typename _InputIterator>
-    _GLIBCXX_CONSTEXPR
     inline bool
     __valid_range_aux(_InputIterator __first, _InputIterator __last,
                      std::__false_type)
+#endif
     {
       return __gnu_debug::__valid_range_aux(__first, __last,
                                            std::__iterator_category(__first));
     }
 
+#if __cplusplus >= 201103L
   template<typename _InputIterator>
     _GLIBCXX20_CONSTEXPR
+    inline bool
+    __valid_range(_InputIterator __first, _InputIterator __last,
+                 typename _Distance_traits<_InputIterator>::__type& __dist)
+#else
+  template<typename _InputIterator>
     inline bool
     __valid_range_aux(_InputIterator __first, _InputIterator __last,
                      typename _Distance_traits<_InputIterator>::__type& __dist,
                      std::__false_type)
+#endif
     {
       if (!__gnu_debug::__valid_range_aux(__first, __last,
                                          std::input_iterator_tag()))
@@ -232,13 +249,13 @@ namespace __gnu_debug
       return true;
     }
 
+#if __cplusplus < 201103L
   /** Don't know what these iterators are, or if they are even
    *  iterators (we may get an integral type for InputIterator), so
    *  see if they are integral and pass them on to the next phase
    *  otherwise.
   */
   template<typename _InputIterator>
-    _GLIBCXX20_CONSTEXPR
     inline bool
     __valid_range(_InputIterator __first, _InputIterator __last,
                  typename _Distance_traits<_InputIterator>::__type& __dist)
@@ -247,6 +264,7 @@ namespace __gnu_debug
       return __gnu_debug::__valid_range_aux(__first, __last, __dist,
                                            _Integral());
     }
+#endif
 
   template<typename _Iterator, typename _Sequence, typename _Category>
     _GLIBCXX20_CONSTEXPR bool
@@ -262,14 +280,15 @@ namespace __gnu_debug
                  typename _Distance_traits<_Iterator>::__type&);
 #endif
 
+#if __cplusplus < 201103L
   template<typename _InputIterator>
-    _GLIBCXX14_CONSTEXPR
     inline bool
     __valid_range(_InputIterator __first, _InputIterator __last)
     {
       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
       return __gnu_debug::__valid_range_aux(__first, __last, _Integral());
     }
+#endif
 
   template<typename _Iterator, typename _Sequence, typename _Category>
     _GLIBCXX20_CONSTEXPR bool