Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ static bool hasRValueOverload(const CXXConstructorDecl *Ctor,
};

for (const auto *Candidate : Record->ctors()) {
if (IsRValueOverload(Candidate)) {
if (IsRValueOverload(Candidate))
return true;
}
}
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"

#include <memory>

namespace clang::tidy::modernize {

class PassByValueCheck : public ClangTidyCheck {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ struct A {
Movable GlobalObj;
struct B {
B(const Movable &M) : M(GlobalObj) {}
// CHECK-FIXES: B(const Movable &M) : M(GlobalObj) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
Movable M;
};

// Test that a parameter with more than one reference to it won't be changed.
struct C {
// Tests extra-reference in body.
C(const Movable &M) : M(M) { this->i = M.a; }
// CHECK-FIXES: C(const Movable &M) : M(M) { this->i = M.a; }
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move

// Tests extra-reference in init-list.
C(const Movable &M, int) : M(M), i(M.a) {}
// CHECK-FIXES: C(const Movable &M, int) : M(M), i(M.a) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
Movable M;
int i;
};
Expand All @@ -70,7 +70,7 @@ struct E {
// Test with object that can't be moved.
struct F {
F(const NotMovable &NM) : NM(NM) {}
// CHECK-FIXES: F(const NotMovable &NM) : NM(NM) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
NotMovable NM;
};

Expand Down Expand Up @@ -112,7 +112,8 @@ struct I {
// Test that templates aren't modified.
template <typename T> struct J {
J(const T &M) : M(M) {}
// CHECK-FIXES: J(const T &M) : M(M) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
// CHECK-FIXES-NOT: J(T M) : M(std::move(M)) {}
T M;
};
J<Movable> j1(Movable());
Expand All @@ -129,13 +130,14 @@ struct MovableTemplateT
template <class T>
struct J2 {
J2(const MovableTemplateT<T>& A);
// CHECK-FIXES: J2(const MovableTemplateT<T>& A);
// CHECK-FIXES-NOT: J2(MovableTemplateT<T> A);
MovableTemplateT<T> M;
};

template <class T>
J2<T>::J2(const MovableTemplateT<T>& A) : M(A) {}
// CHECK-FIXES: J2<T>::J2(const MovableTemplateT<T>& A) : M(A) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:11: warning: pass by value and use std::move
// CHECK-FIXES-NOT: J2<T>::J2(MovableTemplateT<T> A) : M(std::move(A)) {}
J2<int> j3(MovableTemplateT<int>{});

struct K_Movable {
Expand Down Expand Up @@ -182,7 +184,7 @@ struct O {
// Test with a const-value parameter.
struct P {
P(const Movable M) : M(M) {}
// CHECK-FIXES: P(const Movable M) : M(M) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
Movable M;
};

Expand Down Expand Up @@ -215,7 +217,7 @@ struct R {
// Test with rvalue parameter.
struct S {
S(Movable &&M) : M(M) {}
// CHECK-FIXES: S(Movable &&M) : M(M) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
Movable M;
};

Expand All @@ -225,13 +227,13 @@ template <typename T, int N> struct array { T A[N]; };
// cause problems with performance-move-const-arg, as it will revert it.
struct T {
T(array<int, 10> a) : a_(a) {}
// CHECK-FIXES: T(array<int, 10> a) : a_(a) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
array<int, 10> a_;
};

struct U {
U(const POD &M) : M(M) {}
// CHECK-FIXES: U(const POD &M) : M(M) {}
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
POD M;
};

Expand Down
Loading