[Bug c++/86521] [8/9 Regression] GCC 8 selects incorrect overload of ref-qualified conversion operator template

jason at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 12 03:38:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86521

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Jason Merrill from comment #4)
> The cast is ambiguous
> 
> To construct a 'base', we consider the two constructors
> 
> 1) base(const base&);
> 2) base(base&&);
> 
> for each of them we could convert the argument by either
> 
> 3) operator U () &&
> 4) operator U const& () const&
> 
> For #1 we want to convert to const base&.  For direct reference binding, #4
> is the only candidate, and it is viable.  For #2 we want to convert to
> base&&, only #3 is a candidate for direct reference binding, and it is
> viable.
> 
> The two user-defined conversion sequences are not comparable because they
> use different conversion operators, so the initialization is ambiguous.

...although perhaps the C++17 mandatory copy elision should alter this
calculation: initializing the object from the result of #3 doesn't actually use
the copy constructor.  In that case, we'd just be using #3, making it better
than #4+#2.  The standard doesn't currently say this, but it probably should.


More information about the Gcc-bugs mailing list