|
Boost : |
Subject: Re: [boost] Constructing string_ref from rvalue string
From: Jonathan Coe (jbcoe_at_[hidden])
Date: 2017-03-20 07:03:15
> On 20 Mar 2017, at 03:14, Tim Song via Boost <boost_at_[hidden]> wrote:
>
> On Sun, Mar 19, 2017 at 10:42 PM, Gavin Lambert via Boost
> <boost_at_[hidden]> wrote:
>>
>> If you are calling a function that returns a std::string (thus you have an
>> rvalue temporary) and you are immediately wrapping this in a string_ref (as
>> another temporary) and then passing this as a function parameter, AFAIK the
>> compiler is within its rights to delete the temporary std::string prior to
>> the call as it is not the actual parameter.
>
> Nope. Those temporaries live until the end of the enclosing full-expression.
>
I thought it worth bringing to your attention that clang-tidy has a check to find misuse of string_view construction from temporaries: http://clang.llvm.org/extra/clang-tidy/checks/misc-dangling-handle.html
Regards
Jonathan
> _______________________________________________
> 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