[clang-tools-extra] 0aaac4f - [clang-tidy][performance-move-const-arg] Fix crash when argument type has no definition (#111472)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 15:16:46 PDT 2024
Author: Nicolas van Kempen
Date: 2024-10-09T18:16:43-04:00
New Revision: 0aaac4fe194ae2249e1a01f9d6f5eac0d75c5bb2
URL: https://github.com/llvm/llvm-project/commit/0aaac4fe194ae2249e1a01f9d6f5eac0d75c5bb2
DIFF: https://github.com/llvm/llvm-project/commit/0aaac4fe194ae2249e1a01f9d6f5eac0d75c5bb2.diff
LOG: [clang-tidy][performance-move-const-arg] Fix crash when argument type has no definition (#111472)
Fix #111450.
Added:
Modified:
clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
index d29b9e91f2e35d..421ce003975bc9 100644
--- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -209,8 +209,9 @@ void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
}
if (const CXXRecordDecl *RecordDecl = ArgType->getAsCXXRecordDecl();
- RecordDecl && !(RecordDecl->hasMoveConstructor() &&
- RecordDecl->hasMoveAssignment())) {
+ RecordDecl && RecordDecl->hasDefinition() &&
+ !(RecordDecl->hasMoveConstructor() &&
+ RecordDecl->hasMoveAssignment())) {
const bool MissingMoveAssignment = !RecordDecl->hasMoveAssignment();
const bool MissingMoveConstructor = !RecordDecl->hasMoveConstructor();
const bool MissingBoth = MissingMoveAssignment && MissingMoveConstructor;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 51100286724588..3c4652e3c23774 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -210,6 +210,10 @@ Changes in existing checks
<clang-tidy/checks/performance/avoid-endl>` check to use ``std::endl`` as
placeholder when lexer cannot get source text.
+- Improved :doc:`performance-move-const-arg
+ <clang-tidy/checks/performance/move-const-arg>` check to fix a crash when
+ an argument type is declared but not defined.
+
- Improved :doc:`readability-container-contains
<clang-tidy/checks/readability/container-contains>` check to let it work on
any class that has a ``contains`` method.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
index 4505eef6df24bd..8e325b0ae6ca30 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
@@ -546,3 +546,17 @@ void testAlsoNonMoveable() {
}
} // namespace issue_62550
+
+namespace GH111450 {
+struct Status;
+
+struct Error {
+ Error(const Status& S);
+};
+
+struct Result {
+ Error E;
+ Result(Status&& S) : E(std::move(S)) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+};
+} // namespace GH111450
More information about the cfe-commits
mailing list