Boost logo

Boost :

Subject: Re: [boost] [optional] get() misses optional r-value overload in contrast to operator* and value()
From: Viktor Sehr (viktor.sehr_at_[hidden])
Date: 2018-03-23 21:42:24


Clang (6.0) emits "ud2" instructions for both auto&& and const auto&. If
the const auto& can bind directly to an r-value, this must mean Clang is
wrong, or am I missing something?

GCC on the other hand emits code for both functions, although with slight
difference (I'm not skilled enough in assembler to analyze the GCC output
in further detail)

Code example: https://godbolt.org/g/7fjszE <https://godbolt.org/g/uNJoZB>

/Viktor

On Fri, Mar 23, 2018 at 1:06 PM Peter Dimov via Boost <boost_at_[hidden]>
wrote:

> Matt Calabrese wrote:
> > On Fri, Mar 23, 2018 at 12:01 PM, Peter Dimov via Boost
> > <boost_at_[hidden]> wrote:
> > > Interesting question. value() && returns T&&. The auto const& reference
> > > can't bind directly to T&&, because that's not an lvalue.
> >
> > An lvalue-reference-to-const can bind to an rvalue (it's why you can pass
> > an rvalue to a function that takes a "const T&").
>
> You're right, it does bind directly.
> http://eel.is/c++draft/dcl.init.ref#5.3.1
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk