[clang-tools-extra] r295176 - [clang-tidy] Don't warn about call to unresolved operator*

Malcolm Parsons via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 15 06:01:42 PST 2017


Author: malcolm.parsons
Date: Wed Feb 15 08:01:41 2017
New Revision: 295176

URL: http://llvm.org/viewvc/llvm-project?rev=295176&view=rev
Log:
[clang-tidy] Don't warn about call to unresolved operator*

Summary:
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.

Reviewers: alexfh, aaron.ballman

Subscribers: JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D29393

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp?rev=295176&r1=295175&r2=295176&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp Wed Feb 15 08:01:41 2017
@@ -58,7 +58,10 @@ void UnconventionalAssignOperatorCheck::
       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))

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp?rev=295176&r1=295175&r2=295176&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp Wed Feb 15 08:01:41 2017
@@ -87,3 +87,25 @@ public:
     return n;
   }
 };
+
+namespace pr31531 {
+enum E { e };
+// This declaration makes the 'return *this' below have an unresolved operator
+// in the class template, but not in an instantiation.
+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;
+}




More information about the cfe-commits mailing list