This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] add option performance-move-const-arg.CheckMoveToConstRef
ClosedPublic

Authored by devjgm on Feb 9 2022, 1:05 PM.

Details

Summary

This option allows callers to disable the warning from
https://clang.llvm.org/extra/clang-tidy/checks/performance-move-const-arg.html
that would warn on the following

void f(const string &s);
string s;
f(std::move(s));  // ALLOWED if performance-move-const-arg.CheckMoveToConstRef=false

The reason people might want to disable this check, is because it allows
callers to use std::move() or not based on local reasoning about the
argument, and without having to care about how the function f accepts
the argument. Indeed, f might accept the argument by const-ref today,
but change to by-value tomorrow, and if the caller had moved the
argument that they were finished with, the code would work as
efficiently as possible regardless of how f accepted the parameter.

Diff Detail

Event Timeline

devjgm created this revision.Feb 9 2022, 1:05 PM
devjgm requested review of this revision.Feb 9 2022, 1:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2022, 1:05 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
devjgm updated this revision to Diff 407267.Feb 9 2022, 1:20 PM

Here is also updated the documentation to include the new option.

devjgm edited the summary of this revision. (Show Details)Feb 9 2022, 1:23 PM
devjgm added a reviewer: ymandel.
devjgm edited the summary of this revision. (Show Details)
ymandel retitled this revision from feat: add option performance-move-const-arg.CheckMoveToConstRef to [clang-tidy] add option performance-move-const-arg.CheckMoveToConstRef.Feb 9 2022, 1:31 PM
ymandel accepted this revision.Feb 9 2022, 1:41 PM
ymandel added inline comments.
clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
197–198

nit, up to you. I think this way is a little clearer b/c it reads "proceed on this branch if the check is configured to "check move to const ref"".

This revision is now accepted and ready to land.Feb 9 2022, 1:41 PM
devjgm updated this revision to Diff 407288.Feb 9 2022, 2:09 PM

Accepted ymandel's suggestion.

devjgm marked an inline comment as done.Feb 9 2022, 2:09 PM
devjgm updated this revision to Diff 407300.Feb 9 2022, 2:25 PM
  • accepted ymandel's suggestion