Unused struct members: bail out upon casting
This commit is contained in:
parent
fa14dcbf68
commit
2e9f7755ee
|
@ -619,6 +619,11 @@ void CheckOther::checkStructMemberUsage()
|
|||
if (tok2->str() == "}")
|
||||
break;
|
||||
}
|
||||
|
||||
// Bail out if some data is casted to struct..
|
||||
const std::string s("( struct " + tok->next()->str() + " * ) & %var% [");
|
||||
if (Token::findmatch(tok, s.c_str()))
|
||||
structname = 0;
|
||||
}
|
||||
|
||||
if (tok->str() == "}")
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
checkOther.checkUnsignedDivision();
|
||||
checkOther.checkCharVariable();
|
||||
checkOther.checkVariableScope();
|
||||
checkOther.checkStructMemberUsage();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +66,6 @@ public:
|
|||
{
|
||||
checkOther.warningRedundantCode();
|
||||
checkOther.checkConstantFunctionParameter();
|
||||
checkOther.checkStructMemberUsage();
|
||||
checkOther.checkIncompleteStatement();
|
||||
if (settings->_showAll)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,6 @@ private:
|
|||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
@ -58,6 +57,7 @@ private:
|
|||
TEST_CASE(structmember3);
|
||||
TEST_CASE(structmember4);
|
||||
TEST_CASE(structmember5);
|
||||
TEST_CASE(structmember6);
|
||||
}
|
||||
|
||||
void structmember1()
|
||||
|
@ -149,6 +149,22 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void structmember6()
|
||||
{
|
||||
check("struct AB\n"
|
||||
"{\n"
|
||||
" int a;\n"
|
||||
" int b;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void foo(char *buf)\n"
|
||||
"{\n"
|
||||
" struct AB *ab = (struct AB *)&buf[10];\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestUnusedVar)
|
||||
|
|
Loading…
Reference in New Issue