Skip to content

Commit 60c4c04

Browse files
committed
[clang-tidy][nfc] refactor pass-by-value check tests to use check-fixes-not and deleted unused code in the check
1 parent fa24875 commit 60c4c04

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ static bool hasRValueOverload(const CXXConstructorDecl *Ctor,
166166
};
167167

168168
for (const auto *Candidate : Record->ctors()) {
169-
if (IsRValueOverload(Candidate)) {
169+
if (IsRValueOverload(Candidate))
170170
return true;
171-
}
172171
}
173172
return false;
174173
}

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "../ClangTidyCheck.h"
1313
#include "../utils/IncludeInserter.h"
1414

15-
#include <memory>
16-
1715
namespace clang::tidy::modernize {
1816

1917
class PassByValueCheck : public ClangTidyCheck {

clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ struct A {
3232
Movable GlobalObj;
3333
struct B {
3434
B(const Movable &M) : M(GlobalObj) {}
35-
// CHECK-FIXES: B(const Movable &M) : M(GlobalObj) {}
35+
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
3636
Movable M;
3737
};
3838

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

4545
// Tests extra-reference in init-list.
4646
C(const Movable &M, int) : M(M), i(M.a) {}
47-
// CHECK-FIXES: C(const Movable &M, int) : M(M), i(M.a) {}
47+
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
4848
Movable M;
4949
int i;
5050
};
@@ -70,7 +70,7 @@ struct E {
7070
// Test with object that can't be moved.
7171
struct F {
7272
F(const NotMovable &NM) : NM(NM) {}
73-
// CHECK-FIXES: F(const NotMovable &NM) : NM(NM) {}
73+
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
7474
NotMovable NM;
7575
};
7676

@@ -112,7 +112,8 @@ struct I {
112112
// Test that templates aren't modified.
113113
template <typename T> struct J {
114114
J(const T &M) : M(M) {}
115-
// CHECK-FIXES: J(const T &M) : M(M) {}
115+
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
116+
// CHECK-FIXES-NOT: J(T M) : M(std::move(M)) {}
116117
T M;
117118
};
118119
J<Movable> j1(Movable());
@@ -129,13 +130,14 @@ struct MovableTemplateT
129130
template <class T>
130131
struct J2 {
131132
J2(const MovableTemplateT<T>& A);
132-
// CHECK-FIXES: J2(const MovableTemplateT<T>& A);
133+
// CHECK-FIXES-NOT: J2(MovableTemplateT<T> A);
133134
MovableTemplateT<T> M;
134135
};
135136

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

141143
struct K_Movable {
@@ -182,7 +184,7 @@ struct O {
182184
// Test with a const-value parameter.
183185
struct P {
184186
P(const Movable M) : M(M) {}
185-
// CHECK-FIXES: P(const Movable M) : M(M) {}
187+
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
186188
Movable M;
187189
};
188190

@@ -215,7 +217,7 @@ struct R {
215217
// Test with rvalue parameter.
216218
struct S {
217219
S(Movable &&M) : M(M) {}
218-
// CHECK-FIXES: S(Movable &&M) : M(M) {}
220+
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use std::move
219221
Movable M;
220222
};
221223

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

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

0 commit comments

Comments
 (0)