diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 391b3833e..181d2cb9c 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1479,20 +1479,6 @@ void CheckUnusedVar::checkStructMemberUsage() bailout = true; 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) break; } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 22e104f90..d5c4b1ab3 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1677,7 +1677,7 @@ private: " uint8_t* p = (uint8_t*)&s;\n" " return p[10];\n" "};\n"); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (style) struct member 'S::padding' is never used.\n", errout.str()); checkStructMemberUsage("struct S { uint8_t padding[500]; };\n" "uint8_t f(const S& s) {\n" @@ -1685,7 +1685,14 @@ private: " auto p = reinterpret_cast(&s);\n" " return p[10];\n" "};\n"); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (style) struct member 'S::padding' is never used.\n", errout.str()); + + checkStructMemberUsage("struct S { int i, j; };\n" // #11577 + "void f(S s) {\n" + " void* p = (void*)&s;\n" + " if (s.i) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:1]: (style) struct member 'S::j' is never used.\n", errout.str()); } void structmember19() {