[clang-tools-extra] a7395b8 - [clang-tidy] Skip copy assignment operators with nonstandard return types
Alexander Shaposhnikov via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 2 15:43:59 PDT 2022
Author: Alexander Shaposhnikov
Date: 2022-09-02T22:43:39Z
New Revision: a7395b860bc247c9e4e917bf5786c04d4cccf1d7
URL: https://github.com/llvm/llvm-project/commit/a7395b860bc247c9e4e917bf5786c04d4cccf1d7
DIFF: https://github.com/llvm/llvm-project/commit/a7395b860bc247c9e4e917bf5786c04d4cccf1d7.diff
LOG: [clang-tidy] Skip copy assignment operators with nonstandard return types
Skip copy assignment operators with nonstandard return types
since they cannot be defaulted.
Test plan: ninja check-clang-tools
Differential revision: https://reviews.llvm.org/D133006
Added:
Modified:
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
index f321c0b2e693..2de677d2735f 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -8,6 +8,7 @@
#include "UseEqualsDefaultCheck.h"
#include "../utils/LexerUtils.h"
+#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
@@ -247,7 +248,12 @@ void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) {
// isCopyAssignmentOperator() allows the parameter to be
// passed by value, and in this case it cannot be
// defaulted.
- hasParameter(0, hasType(lValueReferenceType())))
+ hasParameter(0, hasType(lValueReferenceType())),
+ // isCopyAssignmentOperator() allows non lvalue reference
+ // return types, and in this case it cannot be defaulted.
+ returns(qualType(hasCanonicalType(
+ allOf(lValueReferenceType(pointee(type())),
+ unless(matchers::isReferenceToConst()))))))
.bind(SpecialFunction),
this);
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index e0907b23c84c..7c91ea00dca8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -145,7 +145,8 @@ Changes in existing checks
check.
The check now skips unions since in this case a default constructor with empty body
- is not equivalent to the explicitly defaulted one. The check is restricted to c++11-or-later.
+ is not equivalent to the explicitly defaulted one. The check also skips copy assignment
+ operators with nonstandard return types. The check is restricted to c++11-or-later.
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp
index 78a03f02eed5..70fc521ebb7a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp
@@ -444,6 +444,13 @@ IL &WRT::operator=(const WRT &Other) {
return *this;
}
+// Wrong return type.
+struct WRTConstRef {
+ const WRTConstRef &operator = (const WRTConstRef &) {
+ return *this;
+ }
+};
+
// Try-catch.
struct ITC {
ITC(const ITC &Other)
More information about the cfe-commits
mailing list