Boost logo

Boost :

From: Gavin Lambert (boost_at_[hidden])
Date: 2021-10-21 00:57:45


On 21/10/2021 13:42, Peter Dimov wrote:
> begin/end don't have this problem in practice because you need to call both,
> and that's hard to do on the same temporary.

It's a constant thorn in Range's side, though, especially with all the
various kinds of non-owning filters. But by the same token people
should start getting more used to these sorts of considerations and be
less prone to making such errors.

And the static analysis tooling is a bit better now at spotting such
things, though not perfect.

> c_str does, but virtually nobody makes this mistake for some reason.

I recall some older (broken) C++ compiler (or rather: optimizer)
implementations where the temporary in (rvalue).c_str() was sometimes
destroyed after calling c_str() instead of after the entire
full-expression, which caused all sorts of Funâ„¢ for the common cases of
passing this to a method call, which in turn led to defensively creating
a lot of otherwise unnecessary lvalues.

Thankfully modern compilers don't have that problem any more.


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