diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 05801b4ad15a..d07ce59f99cb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1560,6 +1560,13 @@ static const Token* getVariableChangedStart(const Variable* p) return start; } +static bool isFunctionPointer(const Token *tok) +{ + if (!tok || !tok->next()) + return false; + return Token::Match(tok->next(), "( * %var% )"); +} + void CheckOther::checkConstPointer() { if (!mSettings->severity.isEnabled(Severity::style)) @@ -1660,7 +1667,7 @@ void CheckOther::checkConstPointer() continue; } } - } else { + } else if (!isFunctionPointer(var->typeStartToken())) { const auto dir = mSettings->library.getArgDirection(ftok, argn + 1); if (dir == Library::ArgumentChecks::Direction::DIR_IN) continue; diff --git a/test/testother.cpp b/test/testother.cpp index b8c48f797a93..4f5209b0d490 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3808,6 +3808,12 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared as pointer to const\n", errout.str()); + + check("void f(void *p, size_t nmemb, size_t size, int (*cmp)(const void *, const void *)) {\n" + " qsort(p, nmemb, size, cmp);\n" + "}\n"); + ASSERT_EQUALS("", + errout.str()); } void switchRedundantAssignmentTest() {