Le 11/01/16 10:51, Andrzej Krzemienski a écrit :
2016-01-11 4:11 GMT+01:00 Gennadiy Rozental
: Benedek Thaler
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: http://melpon.org/wandbox/permlink/yon7EWpj2B5KQNcT
This is a nice web site :) (I should update myself)
The example here is more what is happening:
http://melpon.org/wandbox/permlink/R2obgUazntZM9LVT
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
code is
template<typename T>
binary_expr