Fix #10825 CheckClass::isMemberVar found used member variable with varid 0 (#3863)

* Fix #10825 CheckClass::isMemberVar found used member variable with varid 0

* Restore call to simpleMatch()
This commit is contained in:
chrchr-github 2022-02-28 18:28:23 +01:00 committed by GitHub
parent b1e92fc399
commit 6a8bd981b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -2037,6 +2037,9 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
return true;
} else if (Token::simpleMatch(tok->tokAt(-3), "( * this )")) {
return true;
} else if (Token::Match(tok->tokAt(-3), "%name% ) . %name%")) {
tok = tok->tokAt(-3);
again = true;
} else if (Token::Match(tok->tokAt(-2), "%name% . %name%")) {
tok = tok->tokAt(-2);
again = true;

View File

@ -192,6 +192,7 @@ private:
TEST_CASE(const73); // ticket #10735
TEST_CASE(const74); // ticket #10671
TEST_CASE(const75); // ticket #10065
TEST_CASE(const76); // ticket #10825
TEST_CASE(const_handleDefaultParameters);
TEST_CASE(const_passThisToMemberOfOtherClass);
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
@ -5994,6 +5995,20 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'N::S::f' can be const.\n", errout.str());
}
void const76() { // #10825
checkConst("struct S {\n"
" enum E {};\n"
" void f(const T* t);\n"
" E e;\n"
"};\n"
"struct T { void e(); };\n"
"void S::f(const T* t) {\n"
" const_cast<T*>(t)->e();\n"
"};\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (performance, inconclusive) Technically the member function 'S::f' can be static (but you may consider moving to unnamed namespace).\n",
errout.str());
}
void const_handleDefaultParameters() {
checkConst("struct Foo {\n"
" void foo1(int i, int j = 0) {\n"