[PATCH] D29393: [clang-tidy] Don't warn about call to unresolved operator*
Malcolm Parsons via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 15 06:13:19 PST 2017
This revision was automatically updated to reflect the committed changes.
malcolm.parsons marked 4 inline comments as done.
Closed by commit rL295176: [clang-tidy] Don't warn about call to unresolved operator* (authored by malcolm.parsons).
Changed prior to commit:
https://reviews.llvm.org/D29393?vs=86623&id=88518#toc
Repository:
rL LLVM
https://reviews.llvm.org/D29393
Files:
clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
Index: clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unconventional-assign-operator.cpp
@@ -87,3 +87,25 @@
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;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29393.88518.patch
Type: text/x-patch
Size: 1912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170215/d361bcb6/attachment.bin>
More information about the cfe-commits
mailing list