Fixed #5839 (False positive: Function can be const, if this is passed to functor)

This commit is contained in:
Daniel Marjamäki 2016-09-04 16:36:04 +02:00
parent ce7bfba416
commit 4d22ada078
2 changed files with 15 additions and 1 deletions

View File

@ -1978,7 +1978,10 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
memberAccessed = true; memberAccessed = true;
} }
// Member variable given as parameter // Member variable given as parameter
for (const Token* tok2 = tok1->tokAt(2); tok2 && tok2 != tok1->next()->link(); tok2 = tok2->next()) { const Token *lpar = tok1->next();
if (Token::simpleMatch(lpar, "( ) ("))
lpar = lpar->tokAt(2);
for (const Token* tok2 = lpar->next(); tok2 && tok2 != tok1->next()->link(); tok2 = tok2->next()) {
if (tok2->str() == "(") if (tok2->str() == "(")
tok2 = tok2->link(); tok2 = tok2->link();
else if (tok2->isName() && isMemberVar(scope, tok2)) { else if (tok2->isName() && isMemberVar(scope, tok2)) {

View File

@ -5135,6 +5135,17 @@ private:
" }\n" " }\n"
"};"); "};");
ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static.\n", errout.str());
checkConst("struct A;\n" // #5839 - operator()
"struct B {\n"
" void operator()(A *a);\n"
"};\n"
"struct A {\n"
" void dostuff() {\n"
" B()(this);\n"
" }\n"
"};");
ASSERT_EQUALS("", errout.str());
} }
void assigningPointerToPointerIsNotAConstOperation() { void assigningPointerToPointerIsNotAConstOperation() {