C++ Logo


Advanced search

Subject: Re: Why does overload resolution fail in this simple case?
From: Lénárd Szolnoki (cpp_at_[hidden])
Date: 2020-12-31 04:30:20


On Thu, 31 Dec 2020 09:47:31 +0800
jim x <xmh970252187_at_[hidden]> wrote:

> I think you misread the section [dcl.init.ref]. your example should be
> processed by the paragraph [dcl.init.ref#5.4.1]
> <https://eel.is/c++draft/dcl.init.ref#5.4.1>. So, why you uncomment
> the other function then that would be the best? Because the reference
> be initialized is a lvalue reference, which should be first processed
> by the paragraph [dcl.init.ref#5.1.2]
> <https://eel.is/c++draft/dcl.init.ref#5.1.2> and in this case, the
> candidate functions are formed by [over.match.ref#1.1.1]
> <https://eel.is/c++draft/over.match.ref#1.1.1>. And the set
> constitutes only one member which is `operator const int &() const
> &;`.

Thank you, I think I get this now. What I still don't get is that then
`operator int&&() &&` shouldn't be a candidate here, even if it's the
only conversion function member of S:

struct S
    operator int &&() &&;

void foo() {
    const int& i = S{};

The compilers disagree with me:


Is there still something I miss?


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups