[clang-tidy misc-move-const-arg] more specific messages + suggest alternative solution
llvm-svn: 279666
This commit is contained in:
		
							parent
							
								
									9c3633f516
								
							
						
					
					
						commit
						eedcd9c1ea
					
				| 
						 | 
					@ -74,12 +74,17 @@ void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (IsConstArg || IsTriviallyCopyable) {
 | 
					  if (IsConstArg || IsTriviallyCopyable) {
 | 
				
			||||||
    bool IsVariable = isa<DeclRefExpr>(Arg);
 | 
					    bool IsVariable = isa<DeclRefExpr>(Arg);
 | 
				
			||||||
 | 
					    const auto *Var =
 | 
				
			||||||
 | 
					        IsVariable ? dyn_cast<DeclRefExpr>(Arg)->getDecl() : nullptr;
 | 
				
			||||||
    auto Diag = diag(FileMoveRange.getBegin(),
 | 
					    auto Diag = diag(FileMoveRange.getBegin(),
 | 
				
			||||||
                     "std::move of the %select{|const }0"
 | 
					                     "std::move of the %select{|const }0"
 | 
				
			||||||
                     "%select{expression|variable}1 "
 | 
					                     "%select{expression|variable %4}1 "
 | 
				
			||||||
                     "%select{|of a trivially-copyable type }2"
 | 
					                     "%select{|of the trivially-copyable type %5 }2"
 | 
				
			||||||
                     "has no effect; remove std::move()")
 | 
					                     "has no effect; remove std::move()"
 | 
				
			||||||
                << IsConstArg << IsVariable << IsTriviallyCopyable;
 | 
					                     "%select{| or make the variable non-const}3")
 | 
				
			||||||
 | 
					                << IsConstArg << IsVariable << IsTriviallyCopyable
 | 
				
			||||||
 | 
					                << (IsConstArg && IsVariable && !IsTriviallyCopyable)
 | 
				
			||||||
 | 
					                << Var << Arg->getType();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts());
 | 
					    ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts());
 | 
				
			||||||
  } else if (ReceivingExpr) {
 | 
					  } else if (ReceivingExpr) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,19 +23,19 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int f1() {
 | 
					int f1() {
 | 
				
			||||||
  return std::move(42);
 | 
					  return std::move(42);
 | 
				
			||||||
  // 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-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of the trivially-copyable type 'int' has no effect; remove std::move() [misc-move-const-arg]
 | 
				
			||||||
  // CHECK-FIXES: return 42;
 | 
					  // CHECK-FIXES: return 42;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int f2(int x2) {
 | 
					int f2(int x2) {
 | 
				
			||||||
  return std::move(x2);
 | 
					  return std::move(x2);
 | 
				
			||||||
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of a trivially-copyable type
 | 
					  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x2' of the trivially-copyable type 'int'
 | 
				
			||||||
  // CHECK-FIXES: return x2;
 | 
					  // CHECK-FIXES: return x2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int *f3(int *x3) {
 | 
					int *f3(int *x3) {
 | 
				
			||||||
  return std::move(x3);
 | 
					  return std::move(x3);
 | 
				
			||||||
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of a trivially-copyable type
 | 
					  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x3' of the trivially-copyable type 'int *'
 | 
				
			||||||
  // CHECK-FIXES: return x3;
 | 
					  // CHECK-FIXES: return x3;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,7 +43,7 @@ A f4(A x4) { return std::move(x4); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
A f5(const A x5) {
 | 
					A f5(const A x5) {
 | 
				
			||||||
  return std::move(x5);
 | 
					  return std::move(x5);
 | 
				
			||||||
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable
 | 
					  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [misc-move-const-arg]
 | 
				
			||||||
  // CHECK-FIXES: return x5;
 | 
					  // CHECK-FIXES: return x5;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ void f7() { int a = f6(10); }
 | 
				
			||||||
void f8() {
 | 
					void f8() {
 | 
				
			||||||
  const A a;
 | 
					  const A a;
 | 
				
			||||||
  M1(A b = std::move(a);)
 | 
					  M1(A b = std::move(a);)
 | 
				
			||||||
  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable
 | 
					  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable 'a' has no effect; remove std::move() or make the variable non-const
 | 
				
			||||||
  // CHECK-FIXES: M1(A b = a;)
 | 
					  // CHECK-FIXES: M1(A b = a;)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,7 +64,7 @@ int f9() { return M2(1); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <typename T> T f10(const int x10) {
 | 
					template <typename T> T f10(const int x10) {
 | 
				
			||||||
  return std::move(x10);
 | 
					  return std::move(x10);
 | 
				
			||||||
  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable
 | 
					  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [misc-move-const-arg]
 | 
				
			||||||
  // CHECK-FIXES: return x10;
 | 
					  // CHECK-FIXES: return x10;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
void f11() {
 | 
					void f11() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue