baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: alexfh, hokein.
baloghadamsoftware added subscribers: cfe-commits, xazax.hun.

The return value of every assign operator should be Type&, not only for copy 
and move assign operators. This check and its test was implemented.

http://reviews.llvm.org/D18264

Files:
  clang-tidy/misc/AssignOperatorSignatureCheck.cpp
  test/clang-tidy/misc-assign-operator-signature.cpp

Index: test/clang-tidy/misc-assign-operator-signature.cpp
===================================================================
--- test/clang-tidy/misc-assign-operator-signature.cpp
+++ test/clang-tidy/misc-assign-operator-signature.cpp
@@ -18,6 +18,8 @@
   // 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&);
Index: clang-tidy/misc/AssignOperatorSignatureCheck.cpp
===================================================================
--- clang-tidy/misc/AssignOperatorSignatureCheck.cpp
+++ clang-tidy/misc/AssignOperatorSignatureCheck.cpp
@@ -31,14 +31,17 @@
   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")),
+                    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(


Index: test/clang-tidy/misc-assign-operator-signature.cpp
===================================================================
--- test/clang-tidy/misc-assign-operator-signature.cpp
+++ test/clang-tidy/misc-assign-operator-signature.cpp
@@ -18,6 +18,8 @@
   // 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&);
Index: clang-tidy/misc/AssignOperatorSignatureCheck.cpp
===================================================================
--- clang-tidy/misc/AssignOperatorSignatureCheck.cpp
+++ clang-tidy/misc/AssignOperatorSignatureCheck.cpp
@@ -31,14 +31,17 @@
   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")),
+                    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(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to