public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Fix bug in std::indirect_result_t
@ 2019-12-10 16:16 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2019-12-10 16:16 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

The alias template wasn't working because it applied iter_reference_t to
the pack of iterators before and after passing the pack to the
__indeirect_result helper.

	* include/bits/iterator_concepts.h (indirect_result_t): Do not apply
	iter_reference_t to parameter pack.
	* testsuite/24_iterators/indirect_callable/projected.cc: New test.

Tested powerpc64le-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 4464 bytes --]

commit c87d75745e6a133a2e8e2703cec24d09bc53c636
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Dec 10 15:52:50 2019 +0000

    libstdc++: Fix bug in std::indirect_result_t
    
    The alias template wasn't working because it applied iter_reference_t to
    the pack of iterators before and after passing the pack to the
    __indeirect_result helper.
    
            * include/bits/iterator_concepts.h (indirect_result_t): Do not apply
            iter_reference_t to parameter pack.
            * testsuite/24_iterators/indirect_callable/projected.cc: New test.

diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h
index 97aed72e255..ab9851f19c4 100644
--- a/libstdc++-v3/include/bits/iterator_concepts.h
+++ b/libstdc++-v3/include/bits/iterator_concepts.h
@@ -474,18 +474,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       struct __iter_common_ref
       : common_reference<iter_reference_t<_Tp>, iter_value_t<_Tp>&>
       { };
-
-    // FIXME: needed due to PR c++/67704
-    template<typename _Fn, typename... _Is>
-      struct __indirect_result
-      { };
-
-    template<typename _Fn, typename... _Is>
-      requires (readable<_Is> && ...)
-	&& invocable<_Fn, iter_reference_t<_Is>...>
-      struct __indirect_result<_Fn, _Is...>
-      : invoke_result<_Fn, iter_reference_t<_Is>...>
-      { };
   } // namespace __detail
 
   template<typename _Tp>
@@ -653,15 +641,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       && strict_weak_order<_Fn&, iter_common_reference_t<_I1>,
 			   iter_common_reference_t<_I2>>;
 
+  namespace __detail
+  {
+    // FIXME: needed due to PR c++/67704
+    template<typename _Fn, typename... _Is>
+      struct __indirect_result
+      { };
+
+    template<typename _Fn, typename... _Is>
+      requires (readable<_Is> && ...)
+	&& invocable<_Fn, iter_reference_t<_Is>...>
+      struct __indirect_result<_Fn, _Is...>
+      : invoke_result<_Fn, iter_reference_t<_Is>...>
+      { };
+  } // namespace __detail
+
   template<typename _Fn, typename... _Is>
     using indirect_result_t = typename
-      __detail::__indirect_result<_Fn, iter_reference_t<_Is>...>::type;
+      __detail::__indirect_result<_Fn, _Is...>::type;
 
   /// [projected], projected
   template<readable _Iter, indirectly_regular_unary_invocable<_Iter> _Proj>
     struct projected
     {
       using value_type = remove_cvref_t<indirect_result_t<_Proj&, _Iter>>;
+
       indirect_result_t<_Proj&, _Iter> operator*() const; // not defined
     };
 
diff --git a/libstdc++-v3/testsuite/24_iterators/indirect_callable/projected.cc b/libstdc++-v3/testsuite/24_iterators/indirect_callable/projected.cc
new file mode 100644
index 00000000000..2237314ddc2
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/indirect_callable/projected.cc
@@ -0,0 +1,41 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <iterator>
+
+template<typename T>
+  using PI = std::projected<T, std::identity>;
+
+static_assert(std::same_as<PI<int*>::value_type, int>);
+static_assert(std::same_as<decltype(*std::declval<const PI<int*>&>()), int&>);
+
+struct X
+{
+  using value_type = char*;
+  char* const& operator*() &;
+};
+static_assert( std::readable<X> );
+static_assert(std::same_as<PI<X>::value_type, char*>);
+static_assert(std::same_as<decltype(*std::declval<PI<X>&>()), char* const&>);
+
+struct Y;
+using PY = std::projected<const Y*, int Y::*>;
+static_assert(std::same_as<PY::value_type, int>);
+static_assert(std::same_as<decltype(*std::declval<PY&>()), const int&>);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-12-10 16:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10 16:16 [PATCH] libstdc++: Fix bug in std::indirect_result_t Jonathan Wakely

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).