From f926958acb3b3564959040f06102c667ef577ac5 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Tue, 25 Nov 2014 15:52:52 +0100 Subject: [PATCH] Fix false positive about return type when there's =delete in operator= declaration --- lib/checkclass.cpp | 3 +++ test/testclass.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 3e9088dda..98823b264 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1118,6 +1118,9 @@ void CheckClass::operatorEq() for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { if (func->type == Function::eOperatorEqual && func->access != Private) { + // skip if there's =delete in the declaration - cannot be called anyway + if (func->tokenDef && func->tokenDef->next() && Token::Match(func->tokenDef->next()->link(), ") const| = delete")) + continue; // use definition for check so we don't have to deal with qualification if (!(Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className)) { // make sure we really have a copy assignment operator diff --git a/test/testclass.cpp b/test/testclass.cpp index a38cbd4c8..26cdd8585 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -556,6 +556,14 @@ private: "};"); ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); + checkOpertorEq("class A\n" + "{\n" + "public:\n" + " void goo() {}" + " void operator=(const A&)=delete;\n" + "};"); + ASSERT_EQUALS("", errout.str()); + checkOpertorEq("class A\n" "{\n" "private:\n" @@ -563,6 +571,13 @@ private: "};"); ASSERT_EQUALS("", errout.str()); + checkOpertorEq("class A\n" + "{\n" + "private:\n" + " void operator=(const A&)=delete;\n" + "};"); + ASSERT_EQUALS("", errout.str()); + checkOpertorEq("class A\n" "{\n" " void operator=(const A&);\n" @@ -596,6 +611,12 @@ private: " void operator=(const A&);\n" "};"); ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); + + checkOpertorEq("struct A\n" + "{\n" + " void operator=(const A&)=delete;\n" + "};"); + ASSERT_EQUALS("", errout.str()); } void operatorEq2() {