Subject: Re: [boost] [test] BOOST_TEST macro and std::max
From: Raffi Enficiaud (raffi.enficiaud_at_[hidden])
Date: 2016-01-11 07:46:12
Le 11/01/16 10:51, Andrzej Krzemienski a écrit :
> 2016-01-11 4:11 GMT+01:00 Gennadiy Rozental <rogeeff_at_[hidden]>:
>> Benedek Thaler <thalerbenedek <at> gmail.com> writes:
>> I believe at this point we understand WHAT is going on.
>>> auto const& E = ::boost::test_tools::assertion::seed()->*3u
>>> == ((std::max)(0u, 3u));
>> max returns unsigned int&&, which for some unclear reason is bound to
>> unsigned int const& in expression template E. This obviously becomes
>> dangling reference as soon as we leave this line.
> This is an expected behavior in C++: an xvalue (rvalue reference returned
> from a function) can be bound to a const lvalue reference. See example:
This is a nice web site :) (I should update myself)
The example here is more what is happening:
the "printit" function with an universal ref. The return of std::max
with two identical types is a const lvalue ref according to the standard.
That ref lifetime is expanded until what point?
The "binary_expr" that is returned with boost.test holds that ref. The
binary_expr<ExprType, T, op::EQ<unsigned int, T> >
operator==( T&& rhs )
Is this ref valid at the return of operator== ?
In the case of
auto const& E = ::boost::test_tools::assertion::seed()->*3u ==
((std::max)(0u, 3u)) ;
that ref would exists until " ; ", but if "E" contains an object having
this reference, it is dandling after the " ; ".
Is that correct?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk