Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ void Variable::evaluate(const Settings& settings)
bool isContainer = false;
if (mNameToken) {
setFlag(fIsArray, arrayDimensions(settings, isContainer));
setFlag(fIsMaybeUnused, mNameToken->isAttributeMaybeUnused());
setFlag(fIsMaybeUnused, mNameToken->isAttributeMaybeUnused() || mNameToken->isAttributeUnused());
}


Expand Down
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9663,8 +9663,8 @@ static Token* getVariableTokenAfterAttributes(Token* tok) {
Token *vartok = nullptr;
Token *after = getTokenAfterAttributes(tok, true);

// check if after variable name
if (Token::Match(after, "[;={]")) {
// check if after variable or parameter name
if (Token::Match(after, "[;={,)]")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

Matching , here also changes declarations with several names, not just parameters. int x __attribute__((unused)), y; used to mark y (giving a false unusedVariable for x), and struct S { int a __attribute__((unused)), b; }; used to mark b (hiding unusedStructMember for b). Both are now right, but no test covers them. A test in TestUnusedVar, or a tokenizer test that checks which token gets isAttributeUnused, would protect this fix.

Token *prev = tok->previous();
while (Token::simpleMatch(prev, "]"))
prev = prev->link()->previous();
Expand Down
5 changes: 5 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5020,6 +5020,11 @@ class TestOther : public TestFixture {
"};\n");
ASSERT_EQUALS("[test.cpp:2:17]: (style) Either there is a missing override/final keyword, or the parameter 'p' can be declared as pointer to const [constParameterPointer]\n",
errout_str());

check("void f(int *p __attribute__((unused))) {}\n"
"void g(__attribute__((unused)) int *p) {}\n"
"void h(int *p) {}\n");
ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str());
}

void constArray() {
Expand Down
Loading