C++ Logo

std-discussion

Advanced search

Re: Why does overload resolution fail in this simple case?

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Thu, 31 Dec 2020 10:30:20 +0000
Hi,

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:

https://godbolt.org/z/T9x8Yn

Is there still something I miss?

Regards,
Lénárd

Received on 2020-12-31 04:30:30