parent
9d36dd56a8
commit
8cf5c8fbf2
|
@ -1426,6 +1426,19 @@ void CheckUnusedVar::checkStructMemberUsage()
|
||||||
bailout = true;
|
bailout = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (var && (var->typeStartToken()->str() == scope.className || var->typeEndToken()->str() == scope.className)) {
|
||||||
|
const std::string addressPattern("!!" + scope.className + " & " + var->name()); // cast from struct
|
||||||
|
const Token* addrTok = scope.bodyEnd;
|
||||||
|
do {
|
||||||
|
addrTok = Token::findmatch(addrTok, addressPattern.c_str());
|
||||||
|
if ((addrTok && addrTok->str() == ")" && addrTok->link()->isCast()) || isCPPCast(addrTok)) {
|
||||||
|
bailout = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (addrTok)
|
||||||
|
addrTok = addrTok->next();
|
||||||
|
} while (addrTok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (bailout)
|
if (bailout)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -66,6 +66,7 @@ private:
|
||||||
TEST_CASE(structmember_sizeof);
|
TEST_CASE(structmember_sizeof);
|
||||||
TEST_CASE(structmember16); // #10485
|
TEST_CASE(structmember16); // #10485
|
||||||
TEST_CASE(structmember17); // #10591
|
TEST_CASE(structmember17); // #10591
|
||||||
|
TEST_CASE(structmember18); // #10684
|
||||||
|
|
||||||
TEST_CASE(localvar1);
|
TEST_CASE(localvar1);
|
||||||
TEST_CASE(localvar2);
|
TEST_CASE(localvar2);
|
||||||
|
@ -1607,6 +1608,24 @@ private:
|
||||||
TODO_ASSERT_EQUALS("", "[test.cpp:1]: (style) struct member 'T::i' is never used.\n", errout.str()); // due to removeMacroInClassDef()
|
TODO_ASSERT_EQUALS("", "[test.cpp:1]: (style) struct member 'T::i' is never used.\n", errout.str()); // due to removeMacroInClassDef()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void structmember18() { // #10684
|
||||||
|
checkStructMemberUsage("struct S { uint8_t padding[500]; };\n"
|
||||||
|
"static S s = { 0 };\n"
|
||||||
|
"uint8_t f() {\n"
|
||||||
|
" uint8_t* p = (uint8_t*)&s;\n"
|
||||||
|
" return p[10];\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkStructMemberUsage("struct S { uint8_t padding[500]; };\n"
|
||||||
|
"uint8_t f(const S& s) {\n"
|
||||||
|
" std::cout << &s;\n"
|
||||||
|
" auto p = reinterpret_cast<const uint8_t*>(&s);\n"
|
||||||
|
" return p[10];\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void functionVariableUsage_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
void functionVariableUsage_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
Loading…
Reference in New Issue