[clang-tools-extra] r264251 - [clang-tidy] misc-assign-operator-signature checker checks return value of all assign operators

Gabor Horvath via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 03:12:08 PDT 2016


Author: xazax
Date: Thu Mar 24 05:12:08 2016
New Revision: 264251

URL: http://llvm.org/viewvc/llvm-project?rev=264251&view=rev
Log:
[clang-tidy] misc-assign-operator-signature checker checks return value of all assign operators

The return value of every assign operator should be Type&, not only for copy and move assign operators. 

Patch by Adam Balogh!

Reviewers: hokein, alexfh

Differential Revision: http://reviews.llvm.org/D18264

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp?rev=264251&r1=264250&r2=264251&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp Thu Mar 24 05:12:08 2016
@@ -31,14 +31,16 @@ void AssignOperatorSignatureCheck::regis
   const auto IsSelf = qualType(
       anyOf(hasDeclaration(equalsBoundNode("class")),
             referenceType(pointee(hasDeclaration(equalsBoundNode("class"))))));
-  const auto IsSelfAssign =
+  const auto IsAssign =
       cxxMethodDecl(unless(anyOf(isDeleted(), isPrivate(), isImplicit())),
-                    hasName("operator="), ofClass(recordDecl().bind("class")),
-                    hasParameter(0, parmVarDecl(hasType(IsSelf))))
+                    hasName("operator="), ofClass(recordDecl().bind("class")))
+          .bind("method");
+  const auto IsSelfAssign =
+      cxxMethodDecl(IsAssign, hasParameter(0, parmVarDecl(hasType(IsSelf))))
           .bind("method");
 
   Finder->addMatcher(
-      cxxMethodDecl(IsSelfAssign, unless(HasGoodReturnType)).bind("ReturnType"),
+      cxxMethodDecl(IsAssign, unless(HasGoodReturnType)).bind("ReturnType"),
       this);
 
   const auto BadSelf = referenceType(
@@ -58,14 +60,13 @@ void AssignOperatorSignatureCheck::regis
 
 void AssignOperatorSignatureCheck::check(
     const MatchFinder::MatchResult &Result) {
-  const auto* Method = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
+  const auto *Method = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
   std::string Name = Method->getParent()->getName();
 
   static const char *const Messages[][2] = {
       {"ReturnType", "operator=() should return '%0&'"},
       {"ArgumentType", "operator=() should take '%0 const&', '%0&&' or '%0'"},
-      {"cv", "operator=() should not be marked '%1'"}
-  };
+      {"cv", "operator=() should not be marked '%1'"}};
 
   for (const auto &Message : Messages) {
     if (Result.Nodes.getNodeAs<Decl>(Message[0]))

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp?rev=264251&r1=264250&r2=264251&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp Thu Mar 24 05:12:08 2016
@@ -18,6 +18,8 @@ struct BadReturn {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'BadReturn&' [misc-assign-operator-signature]
   const BadReturn& operator=(BadReturn&&);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'Bad
+  void operator=(int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'Bad
 };
 struct BadReturn2 {
   BadReturn2&& operator=(const BadReturn2&);




More information about the cfe-commits mailing list