[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
https://github.com/carlosgalvezp closed https://github.com/llvm/llvm-project/pull/140753 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
https://github.com/carlosgalvezp approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/140753 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
carlosgalvezp wrote: Thanks, I didn't notice they were the same. In that case they should be removed and have nothing. Optionally one can add a human-readable comment like "Should not trigger here" or something, but it's not necessary. https://github.com/llvm/llvm-project/pull/140753 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
vbvictor wrote: > Also, CHECK-MESSAGES-NOT is discouraged, since the testing framework already > checks that no other output is produced by default. So if CHECK-FIXES are the same as previous code, we can remove them completely (I changed them to CHECK-MESSAGES-NOT) https://github.com/llvm/llvm-project/pull/140753 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
carlosgalvezp wrote: Also, CHECK-MESSAGES-NOT is discouraged, since the testing framework already checked that no other output is produced by default. https://github.com/llvm/llvm-project/pull/140753 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
https://github.com/carlosgalvezp requested changes to this pull request. Why are the fixes being removed? CHECK-FIXES is not equivalent to CHECK-MESSAGES-NOT https://github.com/llvm/llvm-project/pull/140753 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
llvmbot wrote:
@llvm/pr-subscribers-clang-tidy
Author: Baranov Victor (vbvictor)
Changes
- Deleted unused includes
- Deleted useless braces
- Modernized tests to use `CHECK-MESSAGES-NOT` and `CHECK-FIXES-NOT` for better
readability and maintainability
---
Full diff: https://github.com/llvm/llvm-project/pull/140753.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp (+1-2)
- (modified) clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h (-2)
- (modified)
clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp (+13-11)
``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index 7a9d04bfa8ba1..35f90fb8da15b 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -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;
}
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
index c7677edc37dc4..b586b8d5fbf66 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
@@ -12,8 +12,6 @@
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
-#include
-
namespace clang::tidy::modernize {
class PassByValueCheck : public ClangTidyCheck {
diff --git
a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
index c0ebaebe4ccf6..4977186478793 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
@@ -32,7 +32,7 @@ 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;
};
@@ -40,11 +40,11 @@ struct B {
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;
};
@@ -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;
};
@@ -112,7 +112,8 @@ struct I {
// Test that templates aren't modified.
template 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 j1(Movable());
@@ -129,13 +130,14 @@ struct MovableTemplateT
template
struct J2 {
J2(const MovableTemplateT& A);
- // CHECK-FIXES: J2(const MovableTemplateT& A);
+ // CHECK-FIXES-NOT: J2(MovableTemplateT A);
MovableTemplateT M;
};
template
J2::J2(const MovableTemplateT& A) : M(A) {}
-// CHECK-FIXES: J2::J2(const MovableTemplateT& A) : M(A) {}
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:11: warning: pass by value and use
std::move
+// CHECK-FIXES-NOT: J2::J2(MovableTemplateT A) : M(std::move(A)) {}
J2 j3(MovableTemplateT{});
struct K_Movable {
@@ -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;
};
@@ -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;
};
@@ -225,13 +227,13 @@ template struct array { T A[N]; };
// cause problems with performance-move-const-arg, as it will revert it.
struct T {
T(array a) : a_(a) {}
- // CHECK-FIXES: T(array a) : a_(a) {}
+ // CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use
std::move
array 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 va
[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)
https://github.com/vbvictor created
https://github.com/llvm/llvm-project/pull/140753
- Deleted unused includes
- Deleted useless braces
- Modernized tests to use `CHECK-MESSAGES-NOT` and `CHECK-FIXES-NOT` for better
readability and maintainability
>From 60c4c0432a47637bedd20a88c60b5a715473c78a Mon Sep 17 00:00:00 2001
From: Baranov Victor
Date: Tue, 20 May 2025 19:02:16 +0300
Subject: [PATCH] [clang-tidy][nfc] refactor pass-by-value check tests to use
check-fixes-not and deleted unused code in the check
---
.../clang-tidy/modernize/PassByValueCheck.cpp | 3 +--
.../clang-tidy/modernize/PassByValueCheck.h | 2 --
.../checkers/modernize/pass-by-value.cpp | 24 ++-
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index 7a9d04bfa8ba1..35f90fb8da15b 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -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;
}
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
index c7677edc37dc4..b586b8d5fbf66 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
@@ -12,8 +12,6 @@
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
-#include
-
namespace clang::tidy::modernize {
class PassByValueCheck : public ClangTidyCheck {
diff --git
a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
index c0ebaebe4ccf6..4977186478793 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
@@ -32,7 +32,7 @@ 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;
};
@@ -40,11 +40,11 @@ struct B {
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;
};
@@ -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;
};
@@ -112,7 +112,8 @@ struct I {
// Test that templates aren't modified.
template 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 j1(Movable());
@@ -129,13 +130,14 @@ struct MovableTemplateT
template
struct J2 {
J2(const MovableTemplateT& A);
- // CHECK-FIXES: J2(const MovableTemplateT& A);
+ // CHECK-FIXES-NOT: J2(MovableTemplateT A);
MovableTemplateT M;
};
template
J2::J2(const MovableTemplateT& A) : M(A) {}
-// CHECK-FIXES: J2::J2(const MovableTemplateT& A) : M(A) {}
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:11: warning: pass by value and use
std::move
+// CHECK-FIXES-NOT: J2::J2(MovableTemplateT A) : M(std::move(A)) {}
J2 j3(MovableTemplateT{});
struct K_Movable {
@@ -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;
};
@@ -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;
};
@@ -225,13 +227,13 @@ template struct array { T A[N]; };
// cause problems with performance-move-const-arg, as it will revert it.
struct T {
T(array a) : a_(a) {}
- // CHECK-FIXES: T(array a) : a_(a) {}
+ // CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: pass by value and use
std::move
array a_;
};
struct U {
