From f2f5b3ebf000db9e6ef40bf5bf7457470d484fc7 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 20 Jul 2010 09:43:27 +0200 Subject: [PATCH] Fixed #1883 (false positive: (style) The function 'A::SetPos' can be const) --- lib/checkclass.cpp | 7 ++++++- test/testclass.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2669a1a89..f5cde8eff 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2368,7 +2368,12 @@ bool CheckClass::checkConstFunc(const std::string &classname, const std::vector< (tok1->str().find("=") == 1 && tok1->str().find_first_of("") == std::string::npos)) { - if (isMemberVar(classname, derivedFrom, varlist, tok1->previous())) + if (tok1->previous()->varId() == 0 && !derivedFrom.empty()) + { + isconst = false; + break; + } + else if (isMemberVar(classname, derivedFrom, varlist, tok1->previous())) { isconst = false; break; diff --git a/test/testclass.cpp b/test/testclass.cpp index c56401fa9..2170604d6 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -3630,6 +3630,27 @@ private: "};\n" ); ASSERT_EQUALS("", errout.str()); + + checkConst("class AA : public P {\n" + "public:\n" + " AA():P(){}\n" + " inline void vSetXPos(int x_)\n" + " {\n" + " UnknownScope::x = x_;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + + checkConst("class AA {\n" + "public:\n" + " AA():P(){}\n" + " inline void vSetXPos(int x_)\n" + " {\n" + " UnknownScope::x = x_;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4]: (style) The function 'AA::vSetXPos' can be const\n", errout.str()); + } void const27() // ticket #1882