Fixed #8990 (False positive: struct member not used (union))
This commit is contained in:
parent
9133f9fe75
commit
bd83630f2e
|
@ -1221,6 +1221,10 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
|
||||
const Token *expr = varDecl ? varDecl : tok->astOperand1();
|
||||
|
||||
// Is variable in lhs a union member?
|
||||
if (tok->previous() && tok->previous()->variable() && tok->previous()->variable()->nameToken()->scope()->type == Scope::eUnion)
|
||||
continue;
|
||||
|
||||
FwdAnalysis fwdAnalysis(mTokenizer->isCPP(), mSettings->library);
|
||||
if (fwdAnalysis.unusedValue(expr, start, scope->bodyEnd)) {
|
||||
if (!bailoutTypeName.empty() && bailoutTypeName != "auto") {
|
||||
|
|
|
@ -161,6 +161,7 @@ private:
|
|||
TEST_CASE(localvarStruct5);
|
||||
TEST_CASE(localvarStruct6);
|
||||
TEST_CASE(localvarStruct7);
|
||||
TEST_CASE(localvarStruct8);
|
||||
TEST_CASE(localvarStructArray);
|
||||
|
||||
TEST_CASE(localvarOp); // Usage with arithmetic operators
|
||||
|
@ -3445,6 +3446,25 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarStruct8() {
|
||||
functionVariableUsage("struct s {\n"
|
||||
" union {\n"
|
||||
" struct {\n"
|
||||
" int fld1 : 16;\n"
|
||||
" int fld2 : 16;\n"
|
||||
" };\n"
|
||||
" int raw;\n"
|
||||
" };\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void foo() {\n"
|
||||
" struct s test;\n"
|
||||
" test.raw = 0x100;\n"
|
||||
" dostuff(test.fld1, test.fld2);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarStructArray() {
|
||||
// #3633 - detect that struct array is assigned a value
|
||||
functionVariableUsage("void f() {\n"
|
||||
|
|
Loading…
Reference in New Issue