alexander-shaposhnikov created this revision. alexander-shaposhnikov added reviewers: njames93, gribozavr2, aaron.ballman. alexander-shaposhnikov created this object with visibility "All Users". Herald added subscribers: carlosgalvezp, xazax.hun. Herald added a project: All. alexander-shaposhnikov requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Skip copy assignment operators with nonstandard return types since they cannot be defaulted. Test plan: ninja check-clang-tools Repository: rL LLVM https://reviews.llvm.org/D133006 Files: 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 Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp @@ -444,6 +444,13 @@ return *this; } +// Wrong return type. +struct WRTConstRef { + const WRTConstRef &operator = (const WRTConstRef &) { + return *this; + } +}; + // Try-catch. struct ITC { ITC(const ITC &Other) Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -139,7 +139,8 @@ - Improved `modernize-use-equals-default <clang-tidy/checks/modernize/use-equals-default.html>`_ check. The check now skips unions since in this case a default constructor with empty body - is not equivalent to the explicitly defaulted one. + is not equivalent to the explicitly defaulted one. The check also skips + copy assignment operators with nonstandard return types. Removed checks ^^^^^^^^^^^^^^ Index: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp +++ 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 @@ // 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); }
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp @@ -444,6 +444,13 @@ return *this; } +// Wrong return type. +struct WRTConstRef { + const WRTConstRef &operator = (const WRTConstRef &) { + return *this; + } +}; + // Try-catch. struct ITC { ITC(const ITC &Other) Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -139,7 +139,8 @@ - Improved `modernize-use-equals-default <clang-tidy/checks/modernize/use-equals-default.html>`_ check. The check now skips unions since in this case a default constructor with empty body - is not equivalent to the explicitly defaulted one. + is not equivalent to the explicitly defaulted one. The check also skips + copy assignment operators with nonstandard return types. Removed checks ^^^^^^^^^^^^^^ Index: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp +++ 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 @@ // 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); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits