malcolm.parsons created this revision.
Herald added a subscriber: JDevlieghere.

The misc-unconventional-assign-operator check had a false positive
warning when the 'operator*' in 'return *this' was unresolved.

Change matcher to allow calls to unresolved operator.

Fixes PR31531.


https://reviews.llvm.org/D29393

Files:
  clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
  test/clang-tidy/misc-unconventional-assign-operator.cpp


Index: test/clang-tidy/misc-unconventional-assign-operator.cpp
===================================================================
--- test/clang-tidy/misc-unconventional-assign-operator.cpp
+++ test/clang-tidy/misc-unconventional-assign-operator.cpp
@@ -87,3 +87,21 @@
     return n;
   }
 };
+
+enum E { e };
+E operator*(E, E);
+
+template <typename>
+struct UnresolvedOperator {
+  UnresolvedOperator &operator=(const UnresolvedOperator &) { return *this; }
+};
+
+UnresolvedOperator<int> UnresolvedOperatorInt;
+
+template <typename>
+struct Template {
+  Template &operator=(const Template &) { return this; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: operator=() should always 
return '*this'
+};
+
+Template<int> TemplateInt;
Index: clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===================================================================
--- clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -58,7 +58,10 @@
       this);
 
   const auto IsBadReturnStatement = 
returnStmt(unless(has(ignoringParenImpCasts(
-      unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr()))))));
+      anyOf(unaryOperator(hasOperatorName("*"), 
hasUnaryOperand(cxxThisExpr())),
+            cxxOperatorCallExpr(argumentCountIs(1),
+                                callee(unresolvedLookupExpr()),
+                                hasArgument(0, cxxThisExpr())))))));
   const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
 
   Finder->addMatcher(returnStmt(IsBadReturnStatement, 
forFunction(IsGoodAssign))


Index: test/clang-tidy/misc-unconventional-assign-operator.cpp
===================================================================
--- test/clang-tidy/misc-unconventional-assign-operator.cpp
+++ test/clang-tidy/misc-unconventional-assign-operator.cpp
@@ -87,3 +87,21 @@
     return n;
   }
 };
+
+enum E { e };
+E operator*(E, E);
+
+template <typename>
+struct UnresolvedOperator {
+  UnresolvedOperator &operator=(const UnresolvedOperator &) { return *this; }
+};
+
+UnresolvedOperator<int> UnresolvedOperatorInt;
+
+template <typename>
+struct Template {
+  Template &operator=(const Template &) { return this; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: operator=() should always return '*this'
+};
+
+Template<int> TemplateInt;
Index: clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===================================================================
--- clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -58,7 +58,10 @@
       this);
 
   const auto IsBadReturnStatement = returnStmt(unless(has(ignoringParenImpCasts(
-      unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr()))))));
+      anyOf(unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr())),
+            cxxOperatorCallExpr(argumentCountIs(1),
+                                callee(unresolvedLookupExpr()),
+                                hasArgument(0, cxxThisExpr())))))));
   const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
 
   Finder->addMatcher(returnStmt(IsBadReturnStatement, forFunction(IsGoodAssign))
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to