Boost logo

Boost :

Subject: [boost] Constructing string_ref from rvalue string
From: Simon Sasburg (simon.sasburg_at_[hidden])
Date: 2017-03-17 07:29:13


I've just tested our codebase with the 1.64.0 master snapshot, and i've
encountered an issue which i've tracked down to this commit:

https://github.com/boostorg/utility/commit/9960d9f395b79ee860e39064cd4696
1f76d2cb55

Basically this removes the constructor which allows constructing a
boost::string_ref from an rvalue std::string. I am wondering if this is
really that dangerous. In our codebase we almost exlusively use
boost::string_ref as function parameters, with the understanding that
passed string_refs parameters are only valid within the function body. (so
you need to copy it into an std::string if you need to access it afterwards)
With these constraints i think it is OK to construct a string_ref from an
rvalue std::string because the temporary should live long enough. (but
please correct me if i'm wrong here)

Is the safety (?) added by this commit worth it if it breaks working code?

Simon


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