Skip to content

Commit 28723cc

Browse files
Add flag to specify an alternative to std::move
Since std::move is nothing more than a cast, part of STL and not the language itself, it's easy to provide a custom implementation if one wishes not to include the entirety of <utility>. Added flag (MoveFunction) provides a way to continue using this essential check even with the custom implementation of moving.
1 parent 529508c commit 28723cc

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ void RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
4242
StatementMatcher MoveCallMatcher =
4343
callExpr(
4444
argumentCountIs(1),
45-
anyOf(callee(functionDecl(hasName("::std::move"))),
45+
anyOf(callee(functionDecl(hasName(MoveFunction))),
4646
callee(unresolvedLookupExpr(hasAnyDeclaration(
47-
namedDecl(hasUnderlyingDecl(hasName("::std::move"))))))),
47+
namedDecl(hasUnderlyingDecl(hasName(MoveFunction))))))),
4848
hasArgument(
4949
0, argumentOf(
5050
AllowPartialMove,
@@ -122,14 +122,16 @@ RvalueReferenceParamNotMovedCheck::RvalueReferenceParamNotMovedCheck(
122122
AllowPartialMove(Options.get("AllowPartialMove", false)),
123123
IgnoreUnnamedParams(Options.get("IgnoreUnnamedParams", false)),
124124
IgnoreNonDeducedTemplateTypes(
125-
Options.get("IgnoreNonDeducedTemplateTypes", false)) {}
125+
Options.get("IgnoreNonDeducedTemplateTypes", false)),
126+
MoveFunction(Options.get("MoveFunction", "::std::move")) {}
126127

127128
void RvalueReferenceParamNotMovedCheck::storeOptions(
128129
ClangTidyOptions::OptionMap &Opts) {
129130
Options.store(Opts, "AllowPartialMove", AllowPartialMove);
130131
Options.store(Opts, "IgnoreUnnamedParams", IgnoreUnnamedParams);
131132
Options.store(Opts, "IgnoreNonDeducedTemplateTypes",
132133
IgnoreNonDeducedTemplateTypes);
134+
Options.store(Opts, "MoveFunction", MoveFunction);
133135
}
134136

135137
} // namespace clang::tidy::cppcoreguidelines

clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class RvalueReferenceParamNotMovedCheck : public ClangTidyCheck {
3232
const bool AllowPartialMove;
3333
const bool IgnoreUnnamedParams;
3434
const bool IgnoreNonDeducedTemplateTypes;
35+
const StringRef MoveFunction;
3536
};
3637

3738
} // namespace clang::tidy::cppcoreguidelines

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ Changes in existing checks
327327
<clang-tidy/checks/readability/redundant-smartptr-get>` check by fixing
328328
some false positives involving smart pointers to arrays.
329329

330+
- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
331+
<clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved>` check
332+
by adding a flag to specify the function used for moving instead of
333+
``std::move``.
334+
330335
Removed checks
331336
^^^^^^^^^^^^^^
332337

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ Options
7979
T other = std::forward<T>(t);
8080
}
8181

82+
.. option:: MoveFunction
83+
84+
Specify the function used for moving.
85+
Default is `::std::move`.
86+
8287
This check implements `F.18
8388
<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f18-for-will-move-from-parameters-pass-by-x-and-stdmove-the-parameter>`_
8489
from the C++ Core Guidelines.

0 commit comments

Comments
 (0)