Skip to content

Commit a7faefc

Browse files
Fix #14847 Function pointer argument triggers false positive funcArgNamesDifferentUnnamed (#8653)
1 parent 987d3b4 commit a7faefc

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/checkother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,7 +4043,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent()
40434043
definitions[j] = variable->nameToken();
40444044
}
40454045
// get the declaration (search for first token with varId)
4046-
while (decl && !Token::Match(decl, ",|)|;")) {
4046+
while (decl && !Token::Match(decl, "[,;]")) {
40474047
// skip everything after the assignment because
40484048
// it could also have a varId or be the first
40494049
// token with a varId if there is no name token
@@ -4052,7 +4052,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent()
40524052
break;
40534053
}
40544054
// skip over templates and arrays
4055-
if (decl->link() && decl->str() != "(")
4055+
if (decl->link() && !Token::Match(decl, "[()]"))
40564056
decl = decl->link();
40574057
else if (decl->varId())
40584058
declarations[j] = decl;

test/testother.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12955,6 +12955,10 @@ class TestOther : public TestFixture {
1295512955
"[test.cpp:1:12]: (style, inconclusive) Function 'f' argument 1 names different: declaration 'a' definition '<unnamed>'. [funcArgNamesDifferentUnnamed]\n"
1295612956
"[test.cpp:4:12]: (style, inconclusive) Function 'g' argument 1 names different: declaration '<unnamed>' definition 'b'. [funcArgNamesDifferentUnnamed]\n",
1295712957
errout_str());
12958+
12959+
check("void f(void (*fp)(), int x);\n" // #14847
12960+
"void f(void (*fp)(), int x) {}\n");
12961+
ASSERT_EQUALS("", errout_str());
1295812962
}
1295912963

1296012964
void funcArgOrderDifferent() {

0 commit comments

Comments
 (0)