avoid false positive unused static const struct member (#2598)

This commit is contained in:
Achouv 2020-04-08 18:09:20 +02:00 committed by GitHub
parent e3b644d877
commit 7719e4309d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -1400,6 +1400,8 @@ void CheckUnusedVar::checkStructMemberUsage()
// Check if the struct member variable is used anywhere in the file
if (Token::findsimplematch(mTokenizer->tokens(), (". " + var.name()).c_str()))
continue;
if (Token::findsimplematch(mTokenizer->tokens(), (":: " + var.name()).c_str()))
continue;
unusedStructMemberError(var.nameToken(), scope.className, var.name(), scope.type == Scope::eUnion);
}

View File

@ -511,6 +511,17 @@ private:
" ab.b = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'AB::a' is never used.\n", errout.str());
checkStructMemberUsage("struct A\n"
"{\n"
" static const int a = 0;\n"
"};\n"
"\n"
"int foo()\n"
"{\n"
" return A::a;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void structmember_sizeof() {