From 3c56ef2e9d4ffb92e15fafa0068a4cbc6e1a185d Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Wed, 28 Oct 2026 20:27:18 +0100 Subject: [PATCH] Fix #15153 FP constParameterPointer with unused attribute Unused parameters annotated with the unused attribute were reported as they could be declared as pointer to const, while [[maybe_unused]] parameters were not. --- lib/symboldatabase.cpp | 2 +- lib/tokenize.cpp | 4 ++-- test/testother.cpp | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 78fd044cc7b..26801640e99 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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()); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0ad9ddef1d6..44cf62c3e20 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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, "[;={,)]")) { Token *prev = tok->previous(); while (Token::simpleMatch(prev, "]")) prev = prev->link()->previous(); diff --git a/test/testother.cpp b/test/testother.cpp index e285d8d8bd0..f48c1bc2e96 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {