Author: alexfh Date: Tue Apr 26 14:33:49 2016 New Revision: 267592 URL: http://llvm.org/viewvc/llvm-project?rev=267592&view=rev Log: [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 Added: clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp - copied, changed from r267587, clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp Removed: clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp?rev=267592&r1=267591&r2=267592&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp Tue Apr 26 14:33:49 2016 @@ -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(co 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(), Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst?rev=267592&r1=267591&r2=267592&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst Tue Apr 26 14:33:49 2016 @@ -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 Copied: clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp (from r267587, clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp&r1=267587&r2=267592&rev=267592&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp Tue Apr 26 14:33:49 2016 @@ -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; } Removed: clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp?rev=267591&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp (removed) @@ -1,73 +0,0 @@ -// RUN: %check_clang_tidy %s misc-move-const-arg %t -- -- -std=c++11 - -namespace std { -template <typename> struct remove_reference; - -template <typename _Tp> struct remove_reference { typedef _Tp type; }; - -template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; }; - -template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; }; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t); - -} // namespace std - -class A { -public: - A() {} - A(const A &rhs) {} - A(A &&rhs) {} -}; - -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-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-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-FIXES: return x3; -} - -A f4(A x4) { return std::move(x4); } - -A f5(const A x5) { - return std::move(x5); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable - // CHECK-FIXES: return x5; -} - -template <typename T> T f6(const T x6) { return std::move(x6); } - -void f7() { int a = f6(10); } - -#define M1(x) x -void f8() { - const A a; - M1(A b = std::move(a);) - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable - // CHECK-FIXES: M1(A b = a;) -} - -#define M2(x) std::move(x) -int f9() { return M2(1); } - -template <typename T> T f10(const int x10) { - return std::move(x10); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable - // CHECK-FIXES: return x10; -} -void f11() { - f10<int>(1); - f10<double>(1); -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits