Skip to content

Commit 3c56ef2

Browse files
committed
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.
1 parent ffe7e9b commit 3c56ef2

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ void Variable::evaluate(const Settings& settings)
25602560
bool isContainer = false;
25612561
if (mNameToken) {
25622562
setFlag(fIsArray, arrayDimensions(settings, isContainer));
2563-
setFlag(fIsMaybeUnused, mNameToken->isAttributeMaybeUnused());
2563+
setFlag(fIsMaybeUnused, mNameToken->isAttributeMaybeUnused() || mNameToken->isAttributeUnused());
25642564
}
25652565

25662566

‎lib/tokenize.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9663,8 +9663,8 @@ static Token* getVariableTokenAfterAttributes(Token* tok) {
96639663
Token *vartok = nullptr;
96649664
Token *after = getTokenAfterAttributes(tok, true);
96659665

9666-
// check if after variable name
9667-
if (Token::Match(after, "[;={]")) {
9666+
// check if after variable or parameter name
9667+
if (Token::Match(after, "[;={,)]")) {
96689668
Token *prev = tok->previous();
96699669
while (Token::simpleMatch(prev, "]"))
96709670
prev = prev->link()->previous();

‎test/testother.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5020,6 +5020,11 @@ class TestOther : public TestFixture {
50205020
"};\n");
50215021
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",
50225022
errout_str());
5023+
5024+
check("void f(int *p __attribute__((unused))) {}\n"
5025+
"void g(__attribute__((unused)) int *p) {}\n"
5026+
"void h(int *p) {}\n");
5027+
ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str());
50235028
}
50245029

50255030
void constArray() {

0 commit comments

Comments
 (0)