Fixed #6508 (False positive unusedStructMember - brace initializer)
This commit is contained in:
parent
247192452f
commit
b3c80947ed
|
@ -1364,6 +1364,11 @@ void CheckUnusedVar::checkStructMemberUsage()
|
||||||
if (Token::findmatch(scope->classEnd, castPattern.c_str()))
|
if (Token::findmatch(scope->classEnd, castPattern.c_str()))
|
||||||
continue;
|
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..
|
// Bail out if struct is used in sizeof..
|
||||||
for (const Token *tok = scope->classEnd; nullptr != (tok = Token::findsimplematch(tok, "sizeof ("));) {
|
for (const Token *tok = scope->classEnd; nullptr != (tok = Token::findsimplematch(tok, "sizeof ("));) {
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
TEST_CASE(structmember11); // #4168 - initialization with {} / passed by address to unknown function
|
TEST_CASE(structmember11); // #4168 - initialization with {} / passed by address to unknown function
|
||||||
TEST_CASE(structmember12); // #7179 - FP unused structmember
|
TEST_CASE(structmember12); // #7179 - FP unused structmember
|
||||||
TEST_CASE(structmember13); // #3088 - __attribute__((packed))
|
TEST_CASE(structmember13); // #3088 - __attribute__((packed))
|
||||||
|
TEST_CASE(structmember14); // #6508 - (struct x){1,2,..}
|
||||||
TEST_CASE(structmember_sizeof);
|
TEST_CASE(structmember_sizeof);
|
||||||
|
|
||||||
TEST_CASE(localvar1);
|
TEST_CASE(localvar1);
|
||||||
|
@ -439,6 +440,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void structmember_extern() {
|
||||||
// extern struct => no false positive
|
// extern struct => no false positive
|
||||||
checkStructMemberUsage("extern struct AB\n"
|
checkStructMemberUsage("extern struct AB\n"
|
||||||
|
|
Loading…
Reference in New Issue