From 990a09e486a2fb6170d82580d245e6f013a16904 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 10 Dec 2019 16:15:49 +0000 Subject: [PATCH] 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. From-SVN: r279170 --- libstdc++-v3/ChangeLog | 6 ++++ libstdc++-v3/include/bits/iterator_concepts.h | 30 +++++++++------- .../24_iterators/indirect_callable/projected.cc | 41 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 libstdc++-v3/testsuite/24_iterators/indirect_callable/projected.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6ba082f..f25e040 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2019-12-10 Jonathan Wakely + + * 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. + 2019-12-09 Jonathan Wakely * include/bits/range_access.h (ranges::enable_safe_range): Define. diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index 97aed72..ab9851f 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_value_t<_Tp>&> { }; - - // FIXME: needed due to PR c++/67704 - template - struct __indirect_result - { }; - - template - requires (readable<_Is> && ...) - && invocable<_Fn, iter_reference_t<_Is>...> - struct __indirect_result<_Fn, _Is...> - : invoke_result<_Fn, iter_reference_t<_Is>...> - { }; } // namespace __detail template @@ -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 + struct __indirect_result + { }; + + template + requires (readable<_Is> && ...) + && invocable<_Fn, iter_reference_t<_Is>...> + struct __indirect_result<_Fn, _Is...> + : invoke_result<_Fn, iter_reference_t<_Is>...> + { }; + } // namespace __detail + template using indirect_result_t = typename - __detail::__indirect_result<_Fn, iter_reference_t<_Is>...>::type; + __detail::__indirect_result<_Fn, _Is...>::type; /// [projected], projected template _Proj> struct projected { using value_type = remove_cvref_t>; + 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 0000000..2237314 --- /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 +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +template + using PI = std::projected; + +static_assert(std::same_as::value_type, int>); +static_assert(std::same_as&>()), int&>); + +struct X +{ + using value_type = char*; + char* const& operator*() &; +}; +static_assert( std::readable ); +static_assert(std::same_as::value_type, char*>); +static_assert(std::same_as&>()), char* const&>); + +struct Y; +using PY = std::projected; +static_assert(std::same_as); +static_assert(std::same_as()), const int&>); -- 2.7.4