From: Gabor Horvath Date: Thu, 24 Mar 2016 10:12:08 +0000 (+0000) Subject: [clang-tidy] misc-assign-operator-signature checker checks return value of all assign... X-Git-Tag: llvmorg-3.9.0-rc1~11071 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4530b52a23c194c0423e968ec7c1e9188e5f1912;p=platform%2Fupstream%2Fllvm.git [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 llvm-svn: 264251 --- diff --git a/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp b/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp index fe3942f..1112431 100644 --- a/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/AssignOperatorSignatureCheck.cpp @@ -31,14 +31,16 @@ void AssignOperatorSignatureCheck::registerMatchers( 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::registerMatchers( void AssignOperatorSignatureCheck::check( const MatchFinder::MatchResult &Result) { - const auto* Method = Result.Nodes.getNodeAs("method"); + const auto *Method = Result.Nodes.getNodeAs("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(Message[0])) diff --git a/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp b/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp index 1b85d4b..8609fb9 100644 --- a/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-assign-operator-signature.cpp @@ -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&);