summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2016-04-26 19:33:49 +0000
committerAlexander Kornienko <alexfh@google.com>2016-04-26 19:33:49 +0000
commit900cadd3adb495c08c548b609d530ad3fea9b3e6 (patch)
treefcac681a79474483b4b4d995a287df5dbaf598ae
parent8dc9dcaeaccd3be047740b1f19c4beee33b0f44e (diff)
downloadbcm5719-llvm-900cadd3adb495c08c548b609d530ad3fea9b3e6.tar.gz
bcm5719-llvm-900cadd3adb495c08c548b609d530ad3fea9b3e6.zip
[clang-tidy] Now adding correct misc-move-const-arg documentation ;]
+ brushed the code a bit and renamed the test file to match the check name llvm-svn: 267592
-rw-r--r--clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp19
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc-move-const-arg.rst14
-rw-r--r--clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp (renamed from clang-tools-extra/test/clang-tidy/move-const-arg.cpp)8
3 files changed, 20 insertions, 21 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp b/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp
index f38b49be8ea..d8e817523b8 100644
--- a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp
@@ -20,16 +20,15 @@ using namespace ast_matchers;
void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
- Finder->addMatcher(callExpr(unless(isInTemplateInstantiation()),
- callee(functionDecl(hasName("::std::move"))))
+ Finder->addMatcher(callExpr(callee(functionDecl(hasName("::std::move"))),
+ argumentCountIs(1),
+ unless(isInTemplateInstantiation()))
.bind("call-move"),
this);
}
void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) {
const auto *CallMove = Result.Nodes.getNodeAs<CallExpr>("call-move");
- if (CallMove->getNumArgs() != 1)
- return;
const Expr *Arg = CallMove->getArg(0);
SourceManager &SM = Result.Context->getSourceManager();
@@ -43,12 +42,12 @@ void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) {
if (!FileMoveRange.isValid())
return;
bool IsVariable = isa<DeclRefExpr>(Arg);
- auto Diag =
- diag(FileMoveRange.getBegin(), "std::move of the %select{|const }0"
- "%select{expression|variable}1 "
- "%select{|of trivially-copyable type }2"
- "has no effect; remove std::move()")
- << IsConstArg << IsVariable << IsTriviallyCopyable;
+ auto Diag = diag(FileMoveRange.getBegin(),
+ "std::move of the %select{|const }0"
+ "%select{expression|variable}1 "
+ "%select{|of a trivially-copyable type }2"
+ "has no effect; remove std::move()")
+ << IsConstArg << IsVariable << IsTriviallyCopyable;
auto BeforeArgumentsRange = Lexer::makeFileCharRange(
CharSourceRange::getCharRange(CallMove->getLocStart(),
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-move-const-arg.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-move-const-arg.rst
index b09e0a1cf23..86dd9fa0670 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc-move-const-arg.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc-move-const-arg.rst
@@ -3,13 +3,13 @@
misc-move-const-arg
===================
-The check warns if the result of ``std::move(x)`` is bound to a constant
-reference argument, e.g.:
+The check warns if ``std::move()`` is called with a constant argument or an
+argument of a trivially-copyable type, e.g.:
.. code:: c++
- void f(const string&);
- void g() {
- string s;
- F(std::move(s)); // Warning here. std::move() is not moving anything.
- }
+ const string s;
+ return std::move(s); // Warning: std::move of the const variable has no effect
+
+ int x;
+ return std::move(x); // Warning: std::move of the variable of a trivially-copyable type has no effect
diff --git a/clang-tools-extra/test/clang-tidy/move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp
index 015c1a39049..beb4078bdbe 100644
--- a/clang-tools-extra/test/clang-tidy/move-const-arg.cpp
+++ b/clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-move-const-arg %t -- -- -std=c++11
+// RUN: %check_clang_tidy %s misc-move-const-arg %t
namespace std {
template <typename> struct remove_reference;
@@ -23,19 +23,19 @@ public:
int f1() {
return std::move(42);
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of trivially-copyable type has no effect; remove std::move() [misc-move-const-arg]
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of a trivially-copyable type has no effect; remove std::move() [misc-move-const-arg]
// CHECK-FIXES: return 42;
}
int f2(int x2) {
return std::move(x2);
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of trivially-copyable type
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of a trivially-copyable type
// CHECK-FIXES: return x2;
}
int *f3(int *x3) {
return std::move(x3);
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of trivially-copyable type
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of a trivially-copyable type
// CHECK-FIXES: return x3;
}
OpenPOWER on IntegriCloud