[cfe-dev] NRVO warnings

Kim Gräsman kim.grasman at gmail.com
Thu Oct 31 12:19:58 PDT 2013


On Thu, Oct 31, 2013 at 7:59 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Thu, Oct 31, 2013 at 10:06 AM, Reid Kleckner <rnk at google.com> wrote:
>>
>> Personally, I'd be happy to move, but it's not much trouble for me.  :)
>> The only thing I don't like about C++11 so far from reading lld is to see
>> std::move slapped on every return value under the sun.  =P
>
> Hmm. There's 23 matches for 'return std::move' in lld. Of those, 12 uses of
> std::move are redundant (and in fact harmful, since they're suppressing
> NRVO). 8 others will become redundant in C++14. The other 3 are performing
> some non-trivial ownership transfer.
>
> I've been intending to add a warning to Clang for calls to std::move that
> suppress NRVO. Seems like it'd have value here. And then you'd have to read
> 'return std::move(...);' less =)

This sounds like a great idea.

I've been thinking about a related off-by-default warning that fires
whenever NRVO "fails", as a diagnostic optimization tool. But maybe
the false positive rate (i.e. the places where we return by value and
don't care about NRVO) would be too high?

- Kim



More information about the cfe-dev mailing list