Fixed #6508 (False positive unusedStructMember - brace initializer)

This commit is contained in:
Daniel Marjamäki 2017-11-12 22:33:17 +01:00
parent 247192452f
commit b3c80947ed
2 changed files with 14 additions and 0 deletions

View File

@ -1364,6 +1364,11 @@ void CheckUnusedVar::checkStructMemberUsage()
if (Token::findmatch(scope->classEnd, castPattern.c_str()))
continue;
// (struct S){..}
const std::string initPattern("( struct| " + scope->className + " ) {");
if (Token::findmatch(scope->classEnd, initPattern.c_str()))
continue;
// Bail out if struct is used in sizeof..
for (const Token *tok = scope->classEnd; nullptr != (tok = Token::findsimplematch(tok, "sizeof ("));) {
tok = tok->tokAt(2);

View File

@ -51,6 +51,7 @@ private:
TEST_CASE(structmember11); // #4168 - initialization with {} / passed by address to unknown function
TEST_CASE(structmember12); // #7179 - FP unused structmember
TEST_CASE(structmember13); // #3088 - __attribute__((packed))
TEST_CASE(structmember14); // #6508 - (struct x){1,2,..}
TEST_CASE(structmember_sizeof);
TEST_CASE(localvar1);
@ -439,6 +440,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void structmember14() { // #6508
checkStructMemberUsage("struct bstr { char *bstart; size_t len; };\n"
"struct bstr bstr0(void) {\n"
" return (struct bstr){\"hello\",6};\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void structmember_extern() {
// extern struct => no false positive
checkStructMemberUsage("extern struct AB\n"