This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 3/3] libstdc++: Implement C++20 range adaptors


Hi Stephan,

On Mon, 17 Feb 2020, Stephan Bergmann wrote:

> On 04/02/2020 03:07, Patrick Palka wrote:
> > This patch implements [range.adaptors].  It also includes the changes from
> > P3280
> > and P3278 and P3323, without which many standard examples won't work.
> 
> I see that with this
> <https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;a=commit;h=cba9ef069e58eac00f30489d3ef21390caee6e45>
> "libstdc++: Implement C++20 range adaptors", compiling <ranges> with recent
> Clang trunk (which appears to mostly implement C++20 concepts now) in
> -std=c++2a mode fails as below (besides also failing due to some "missing"
> typenames, where Clang apparently doesn't yet implement P0634R3).  And I'm not
> sure which of Clang vs. GCC is right here.
> 
> The failure is
> 
> > gcc/trunk/inst/include/c++/10.0.1/ranges:1512:47: error: ambiguous deduction
> > for template arguments of '_RangeAdaptor'
> >     inline constexpr __adaptor::_RangeAdaptor filter
> >                                               ^
> > gcc/trunk/inst/include/c++/10.0.1/ranges:1073:2: note: candidate function
> > [with _Callable = std::ranges::views::(lambda at
> > gcc/trunk/inst/include/c++/10.0.1/ranges:1513:9)]
> >         _RangeAdaptor(const _Callable& = {})
> >         ^
> > gcc/trunk/inst/include/c++/10.0.1/ranges:1078:2: note: candidate function
> > [with _Callable = std::ranges::views::(lambda at
> > gcc/trunk/inst/include/c++/10.0.1/ranges:1513:9)]
> >         _RangeAdaptor(_Callable __callable)
> >         ^
> 
> and a stripped-down reproducer is
> 
> > template<typename T> struct S {
> >   S(T const &) requires true;
> >   S(T) requires false;
> > };
> > S s = 0;
> 
> (Clang accepts this when the last line is replaced with
> 
> > S<int> s = 0;
> 
> and thus no class template argument deduction needs to be done.)
> 
> I think what is relevant here is [over.match.class.deduct]/1 in the current
> spec, which specifies a helper set of hypothetical function templates based on
> a class' constructors for class template argument deduction.  It details the
> function templates' template parameters, function parameters, and return
> types, but does not mention requires-clauses.  From my superficial
> understanding of concepts and class template argument deduction it would thus
> look like the constructors' requires-clauses should indeed not be taken into
> account here?

Thanks for letting me know about this issue.  That would be my
interpretation of the spec, too.  Maybe someone else could shed light on
this question?

The following patch simplifies _RangeAdaptor's constructors to no longer
need to be constrained and should resolve the deduction ambiguity error
reported by Clang?  Unfortunately the patch triggers an ICE in GCC,
which I'll look into tomorrow.

-- >8 --

Subject: [PATCH] Simplify constructors of _RangeAdaptor

---
 libstdc++-v3/include/std/ranges | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 6759f9b4b46..a04387a75c4 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -1064,19 +1064,13 @@ namespace views
       struct _RangeAdaptor
       {
       protected:
-	[[no_unique_address]]
-	  conditional_t<!is_default_constructible_v<_Callable>,
-			_Callable, __detail::_Empty> _M_callable;
+	[[no_unique_address]] _Callable _M_callable;
 
       public:
-	constexpr
-	_RangeAdaptor(const _Callable& = {})
-	  requires is_default_constructible_v<_Callable>
-	{ }
+	_RangeAdaptor() = default;
 
 	constexpr
 	_RangeAdaptor(_Callable __callable)
-	  requires (!is_default_constructible_v<_Callable>)
 	  : _M_callable(std::move(__callable))
 	{ }
 
-- 
2.25.1.291.ge68e29171c


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]