public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-4834] libstdc++: Missing constexpr for __gnu_debug::__valid_range etc
Date: Mon,  1 Nov 2021 23:51:18 +0000 (GMT)	[thread overview]
Message-ID: <20211101235118.8E4913858004@sourceware.org> (raw)

https://gcc.gnu.org/g:6f34b9e4f1eb7aa3398aaf135cbb24680eaad1b1

commit r12-4834-g6f34b9e4f1eb7aa3398aaf135cbb24680eaad1b1
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Nov 1 12:27:43 2021 +0000

    libstdc++: Missing constexpr for __gnu_debug::__valid_range etc
    
    The new 25_algorithms/move/constexpr.cc test fails in debug mode,
    because the debug assertions use the non-constexpr overloads in
    <debug/stl_iterator.h>.
    
    libstdc++-v3/ChangeLog:
    
            * include/debug/stl_iterator.h (__valid_range): Add constexpr
            for C++20. Qualify call to avoid ADL.
            (__get_distance, __can_advance, __unsafe, __base): Likewise.
            * testsuite/25_algorithms/move/constexpr.cc: Also check with
            std::reverse_iterator arguments.

Diff:
---
 libstdc++-v3/include/debug/stl_iterator.h          | 32 ++++++++++++++++------
 .../testsuite/25_algorithms/move/constexpr.cc      | 11 ++++++++
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/debug/stl_iterator.h b/libstdc++-v3/include/debug/stl_iterator.h
index edeb42ebe98..54f7d42b074 100644
--- a/libstdc++-v3/include/debug/stl_iterator.h
+++ b/libstdc++-v3/include/debug/stl_iterator.h
@@ -35,31 +35,38 @@ namespace __gnu_debug
 {
   // Help Debug mode to see through reverse_iterator.
   template<typename _Iterator>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     __valid_range(const std::reverse_iterator<_Iterator>& __first,
 		  const std::reverse_iterator<_Iterator>& __last,
 		  typename _Distance_traits<_Iterator>::__type& __dist)
-    { return __valid_range(__last.base(), __first.base(), __dist); }
+    {
+      return __gnu_debug::__valid_range(__last.base(), __first.base(), __dist);
+    }
 
   template<typename _Iterator>
+    _GLIBCXX20_CONSTEXPR
     inline typename _Distance_traits<_Iterator>::__type
     __get_distance(const std::reverse_iterator<_Iterator>& __first,
 		   const std::reverse_iterator<_Iterator>& __last)
-    { return __get_distance(__last.base(), __first.base()); }
+    { return __gnu_debug::__get_distance(__last.base(), __first.base()); }
 
   template<typename _Iterator, typename _Size>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     __can_advance(const std::reverse_iterator<_Iterator>& __it, _Size __n)
-    { return __can_advance(__it.base(), -__n); }
+    { return __gnu_debug::__can_advance(__it.base(), -__n); }
 
   template<typename _Iterator, typename _Diff>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     __can_advance(const std::reverse_iterator<_Iterator>& __it,
 		  const std::pair<_Diff, _Distance_precision>& __dist,
 		  int __way)
-    { return __can_advance(__it.base(), __dist, -__way); }
+    { return __gnu_debug::__can_advance(__it.base(), __dist, -__way); }
 
   template<typename _Iterator, typename _Sequence>
+    _GLIBCXX20_CONSTEXPR
     inline std::reverse_iterator<_Iterator>
     __base(const std::reverse_iterator<_Safe_iterator<
 	     _Iterator, _Sequence, std::random_access_iterator_tag> >& __it)
@@ -82,6 +89,7 @@ namespace __gnu_debug
     }
 #else
   template<typename _Iterator>
+    _GLIBCXX20_CONSTEXPR
     inline auto
     __unsafe(const std::reverse_iterator<_Iterator>& __it)
     -> decltype(std::__make_reverse_iterator(__unsafe(__it.base())))
@@ -91,37 +99,45 @@ namespace __gnu_debug
 #if __cplusplus >= 201103L
   // Help Debug mode to see through move_iterator.
   template<typename _Iterator>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     __valid_range(const std::move_iterator<_Iterator>& __first,
 		  const std::move_iterator<_Iterator>& __last,
 		  typename _Distance_traits<_Iterator>::__type& __dist)
-    { return __valid_range(__first.base(), __last.base(), __dist); }
+    {
+      return __gnu_debug::__valid_range(__first.base(), __last.base(), __dist);
+    }
 
   template<typename _Iterator>
+    _GLIBCXX20_CONSTEXPR
     inline typename _Distance_traits<_Iterator>::__type
     __get_distance(const std::move_iterator<_Iterator>& __first,
 		   const std::move_iterator<_Iterator>& __last)
-    { return __get_distance(__first.base(), __last.base()); }
+    { return __gnu_debug::__get_distance(__first.base(), __last.base()); }
 
   template<typename _Iterator, typename _Size>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     __can_advance(const std::move_iterator<_Iterator>& __it, _Size __n)
-    { return __can_advance(__it.base(), __n); }
+    { return __gnu_debug::__can_advance(__it.base(), __n); }
 
   template<typename _Iterator, typename _Diff>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     __can_advance(const std::move_iterator<_Iterator>& __it,
 		  const std::pair<_Diff, _Distance_precision>& __dist,
 		  int __way)
-    { return __can_advance(__it.base(), __dist, __way); }
+    { return __gnu_debug::__can_advance(__it.base(), __dist, __way); }
 
   template<typename _Iterator>
+    _GLIBCXX20_CONSTEXPR
     inline auto
     __unsafe(const std::move_iterator<_Iterator>& __it)
     -> decltype(std::make_move_iterator(__unsafe(__it.base())))
     { return std::make_move_iterator(__unsafe(__it.base())); }
 
   template<typename _Iterator>
+    _GLIBCXX20_CONSTEXPR
     inline auto
     __base(const std::move_iterator<_Iterator>& __it)
     -> decltype(std::make_move_iterator(__base(__it.base())))
diff --git a/libstdc++-v3/testsuite/25_algorithms/move/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/move/constexpr.cc
index 773c55cfb50..eb1f3b17e72 100644
--- a/libstdc++-v3/testsuite/25_algorithms/move/constexpr.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/move/constexpr.cc
@@ -17,3 +17,14 @@ test01()
 }
 
 static_assert(test01());
+
+constexpr bool
+test02()
+{
+  int x[2] = {1,2}, y[2];
+  std::span in(x), out(y);
+  std::move(in.rbegin(), in.rend(), out.rbegin());
+  return std::equal(in.rbegin(), in.rend(), out.rbegin());
+}
+
+static_assert(test02());


                 reply	other threads:[~2021-11-01 23:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211101235118.8E4913858004@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).