File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -66,8 +66,11 @@ void UnconventionalAssignOperatorCheck::registerMatchers(
6666 hasArgument (0 , cxxThisExpr ())),
6767 cxxOperatorCallExpr (
6868 hasOverloadedOperatorName (" =" ),
69- hasArgument (
70- 0 , unaryOperator (hasOperatorName (" *" ),
69+ hasArgument (0 , unaryOperator (hasOperatorName (" *" ),
70+ hasUnaryOperand (cxxThisExpr ())))),
71+ binaryOperator (
72+ hasOperatorName (" =" ),
73+ hasLHS (unaryOperator (hasOperatorName (" *" ),
7174 hasUnaryOperand (cxxThisExpr ())))))))));
7275 const auto IsGoodAssign = cxxMethodDecl (IsAssign, HasGoodReturnType);
7376
Original file line number Diff line number Diff line change @@ -208,6 +208,11 @@ Changes in existing checks
208208 <clang-tidy/checks/misc/unused-using-decls>` check by fixing false positives
209209 on ``operator"" `` with template parameters.
210210
211+ - Improved :doc: `misc-unconventional-assign-operator
212+ <clang-tidy/checks/misc/misc-unconventional-assign-operator>` check by fixing
213+ false positives when copy assignment operator function in a template class
214+ returns the result of another assignment to ``*this``(``return *this=... ``).
215+
211216- Improved :doc: `misc-use-internal-linkage
212217 <clang-tidy/checks/misc/use-internal-linkage>` check by fix false positives
213218 for function or variable in header file which contains macro expansion and
Original file line number Diff line number Diff line change @@ -163,3 +163,16 @@ struct TemplateTypeAlias {
163163 Alias3<TypeAlias::Alias> &operator =(double ) { return *this ; }
164164 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'TemplateTypeAlias&' [misc-unconventional-assign-operator]
165165};
166+
167+ namespace issue143237 {
168+ template <typename T>
169+ struct B {
170+ explicit B (int ) {
171+ }
172+
173+ B& operator =(int n) {
174+ // No warning
175+ return *this = B (n);
176+ }
177+ };
178+ }
You can’t perform that action at this time.
0 commit comments