Fix FP unusedVariable with arrays (#5319)

This commit is contained in:
Anton Lindqvist 2023-08-12 16:55:52 +02:00 committed by GitHub
parent b9cc138e57
commit 5c6962c273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -8843,8 +8843,11 @@ void Tokenizer::simplifyAttribute()
// check if after variable name
if (Token::Match(after, ";|=")) {
if (Token::Match(tok->previous(), "%type%"))
vartok = tok->previous();
Token *prev = tok->previous();
while (Token::simpleMatch(prev, "]"))
prev = prev->link()->previous();
if (Token::Match(prev, "%type%"))
vartok = prev;
}
// check if before variable name

View File

@ -5651,6 +5651,13 @@ private:
" bool __attribute__((used)) test;\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("int foo()\n"
"{\n"
" char a[1] __attribute__((unused));\n"
" char b[1][2] __attribute__((unused));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarFunction() {
@ -6199,6 +6206,12 @@ private:
" [[maybe_unused]] [[anotherattribute]] const int* = 1;\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("int main() {\n"
" [[maybe_unused]] char a[1];\n"
" [[maybe_unused]] char b[1][2];\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarthrow() { // ticket #3687