diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1138285ab..ec63858ff 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 527fb5c19..94904a6d6 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -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