avoid false positive unused static const struct member (#2598)
This commit is contained in:
parent
e3b644d877
commit
7719e4309d
|
@ -1400,6 +1400,8 @@ void CheckUnusedVar::checkStructMemberUsage()
|
||||||
// Check if the struct member variable is used anywhere in the file
|
// Check if the struct member variable is used anywhere in the file
|
||||||
if (Token::findsimplematch(mTokenizer->tokens(), (". " + var.name()).c_str()))
|
if (Token::findsimplematch(mTokenizer->tokens(), (". " + var.name()).c_str()))
|
||||||
continue;
|
continue;
|
||||||
|
if (Token::findsimplematch(mTokenizer->tokens(), (":: " + var.name()).c_str()))
|
||||||
|
continue;
|
||||||
|
|
||||||
unusedStructMemberError(var.nameToken(), scope.className, var.name(), scope.type == Scope::eUnion);
|
unusedStructMemberError(var.nameToken(), scope.className, var.name(), scope.type == Scope::eUnion);
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,6 +511,17 @@ private:
|
||||||
" ab.b = 0;\n"
|
" ab.b = 0;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'AB::a' is never used.\n", errout.str());
|
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() {
|
void structmember_sizeof() {
|
||||||
|
|
Loading…
Reference in New Issue