diff --git a/.selfcheck_suppressions b/.selfcheck_suppressions index 171a5a997d7..3f6486dfd9c 100644 --- a/.selfcheck_suppressions +++ b/.selfcheck_suppressions @@ -3,12 +3,40 @@ missingIncludeSystem checkersReport # warnings in Qt generated code we cannot fix +funcArgNamesDifferent:*/moc_aboutdialog.cpp +funcArgNamesDifferent:*/moc_applicationdialog.cpp +funcArgNamesDifferent:*/moc_applicationlist.cpp funcArgNamesDifferent:*/moc_checkthread.cpp +funcArgNamesDifferent:*/moc_codeeditor.cpp funcArgNamesDifferent:*/moc_codeeditstylecontrols.cpp +funcArgNamesDifferent:*/moc_compliancereportdialog.cpp +funcArgNamesDifferent:*/moc_codeeditstyledialog.cpp +funcArgNamesDifferent:*/moc_fileviewdialog.cpp +funcArgNamesDifferent:*/moc_helpdialog.cpp +funcArgNamesDifferent:*/moc_libraryaddfunctiondialog.cpp +funcArgNamesDifferent:*/moc_librarydialog.cpp +funcArgNamesDifferent:*/moc_libraryeditargdialog.cpp +funcArgNamesDifferent:*/moc_mainwindow.cpp +funcArgNamesDifferent:*/moc_newsuppressiondialog.cpp +funcArgNamesDifferent:*/moc_platforms.cpp +funcArgNamesDifferent:*/moc_projectfile.cpp +funcArgNamesDifferent:*/moc_projectfiledialog.cpp funcArgNamesDifferent:*/moc_resultstree.cpp funcArgNamesDifferent:*/moc_resultsview.cpp +funcArgNamesDifferent:*/moc_scratchpad.cpp +funcArgNamesDifferent:*/moc_settingsdialog.cpp +funcArgNamesDifferent:*/moc_statsdialog.cpp +funcArgNamesDifferent:*/moc_testcppchecklibrarydata.cpp +funcArgNamesDifferent:*/moc_testfilelist.cpp +funcArgNamesDifferent:*/moc_testprojectfile.cpp +funcArgNamesDifferent:*/moc_testresultstree.cpp +funcArgNamesDifferent:*/moc_testtranslationhandler.cpp +funcArgNamesDifferent:*/moc_testxmlreportv2.cpp +funcArgNamesDifferent:*/moc_threaddetails.cpp funcArgNamesDifferent:*/moc_threadhandler.cpp funcArgNamesDifferent:*/moc_threadresult.cpp +funcArgNamesDifferent:*/moc_translationhandler.cpp +funcArgNamesDifferent:*/moc_txtreport.cpp naming-varname:*/gui/ui_*.h functionStatic:*/gui/ui_*.h @@ -37,7 +65,9 @@ invalidPrintfArgType_sint:externals/tinyxml2/tinyxml2.h naming-privateMemberVariable:externals/tinyxml2/tinyxml2.h functionStatic:externals/tinyxml2/tinyxml2.cpp funcArgNamesDifferent:externals/tinyxml2/tinyxml2.cpp +funcArgNamesDifferent:externals/tinyxml2/tinyxml2.h nullPointerRedundantCheck:externals/tinyxml2/tinyxml2.cpp knownConditionTrueFalse:externals/tinyxml2/tinyxml2.cpp useStlAlgorithm:externals/simplecpp/simplecpp.cpp +funcArgNamesDifferent:externals/simplecpp/simplecpp.h missingMemberCopy:externals/simplecpp/simplecpp.h diff --git a/gui/codeeditor.h b/gui/codeeditor.h index 4dfbaa66047..00205d1c4e1 100644 --- a/gui/codeeditor.h +++ b/gui/codeeditor.h @@ -129,9 +129,9 @@ class CodeEditor : public QPlainTextEdit { void resizeEvent(QResizeEvent *event) override; private slots: - void updateLineNumberAreaWidth(int newBlockCount); + void updateLineNumberAreaWidth(int /*newBlockCount*/); void highlightErrorLine(); - void updateLineNumberArea(const QRect & /*rect*/, int /*dy*/); + void updateLineNumberArea(const QRect& rect, int dy); private: QString generateStyleString(); diff --git a/gui/librarydialog.h b/gui/librarydialog.h index 285d36a820a..6737da638c8 100644 --- a/gui/librarydialog.h +++ b/gui/librarydialog.h @@ -47,10 +47,10 @@ private slots: void addFunction(); void changeFunction(); void editArg(); - void editFunctionName(QListWidgetItem* /*item*/); - void filterFunctions(const QString& /*filter*/); + void editFunctionName(QListWidgetItem* item); + void filterFunctions(const QString& filter); void selectFunction(); - void sortFunctions(bool /*sort*/); + void sortFunctions(bool sort); private: Ui::LibraryDialog *mUi; diff --git a/gui/projectfiledialog.h b/gui/projectfiledialog.h index 68f62ea83e5..09f69e67763 100644 --- a/gui/projectfiledialog.h +++ b/gui/projectfiledialog.h @@ -275,7 +275,7 @@ private slots: /** * @brief Edit suppression (double clicking on suppression) */ - void editSuppression(const QModelIndex &index); + void editSuppression(const QModelIndex& /*index*/); /** * @brief Browse for misra file diff --git a/gui/threadresult.h b/gui/threadresult.h index 1224b3c539d..87560e87d78 100644 --- a/gui/threadresult.h +++ b/gui/threadresult.h @@ -79,7 +79,7 @@ class ThreadResult : public QObject, public ErrorLogger { /** * ErrorLogger methods */ - void reportOut(const std::string &outmsg, Color c = Color::Reset) override; + void reportOut(const std::string &outmsg, Color /*c*/ = Color::Reset) override; void reportErr(const ErrorMessage &msg) override; void reportMetric(const std::string &metric) override { diff --git a/lib/checkclass.h b/lib/checkclass.h index 1276b212518..6cdea8d581c 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -138,7 +138,7 @@ class CPPCHECKLIB CheckClass : public Check { void checkUnsafeClassRefMember(); /** @brief Parse current TU and extract file info */ - Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings &settings, const std::string& currentConfig) const override; + Check::FileInfo *getFileInfo(const Tokenizer &tokenizer, const Settings& /*settings*/, const std::string& currentConfig) const override; Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const override; diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index cf8cc4c11a2..c9fb2274252 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -266,7 +266,7 @@ class CPPCHECKLIB CheckMemoryLeakStructMember : public Check, private CheckMemor void checkStructVariable(const Variable* variable) const; - void getErrorMessages(ErrorLogger * errorLogger, const Settings * settings) const override; + void getErrorMessages(ErrorLogger* /*errorLogger*/, const Settings* /*settings*/) const override; static std::string myName() { return "Memory leaks (struct members)"; diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 13ad6d29577..b4a2c4f2de2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4061,7 +4061,9 @@ void CheckOther::checkFuncArgNamesDifferent() // check for different argument names if (style && inconclusive) { for (int j = 0; j < function->argCount(); ++j) { - if (declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str()) + const bool warn = (declarations[j] != nullptr) != (definitions[j] != nullptr) || + (declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str()); + if (warn) funcArgNamesDifferent(function->name(), j, declarations[j], definitions[j]); } } @@ -4075,8 +4077,8 @@ void CheckOther::funcArgNamesDifferent(const std::string & functionName, nonneg reportError(tokens, Severity::style, "funcArgNamesDifferent", "$symbol:" + functionName + "\n" "Function '$symbol' argument " + std::to_string(index + 1) + " names different: declaration '" + - (declaration ? declaration->str() : std::string("A")) + "' definition '" + - (definition ? definition->str() : std::string("B")) + "'.", CWE628, Certainty::inconclusive); + (declaration ? declaration->str() : "") + "' definition '" + + (definition ? definition->str() : "") + "'.", CWE628, Certainty::inconclusive); } void CheckOther::funcArgOrderDifferent(const std::string & functionName, diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 882f4588eeb..ee25b7732e4 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1227,7 +1227,7 @@ void CheckStl::invalidContainer() errorPath.insert(errorPath.end(), info.errorPath.cbegin(), info.errorPath.cend()); errorPath.insert(errorPath.end(), r.errorPath.cbegin(), r.errorPath.cend()); if (v) { - invalidContainerError(info.tok, r.tok, v, std::move(errorPath)); + invalidContainerError(info.tok, v, std::move(errorPath)); } else { invalidContainerReferenceError(info.tok, r.tok, std::move(errorPath)); } @@ -1252,7 +1252,7 @@ void CheckStl::invalidContainerLoopError(const Token* tok, const Token* loopTok, reportError(std::move(errorPath), Severity::error, "invalidContainerLoop", msg, CWE664, Certainty::normal); } -void CheckStl::invalidContainerError(const Token *tok, const Token * /*contTok*/, const ValueFlow::Value *val, ErrorPath errorPath) +void CheckStl::invalidContainerError(const Token *tok, const ValueFlow::Value *val, ErrorPath errorPath) { const bool inconclusive = val ? val->isInconclusive() : false; if (val) @@ -3487,7 +3487,7 @@ void CheckStl::getErrorMessages(ErrorLogger* errorLogger, const Settings* settin c.iteratorsError(nullptr, "container1", "container2"); c.iteratorsError(nullptr, nullptr, "container"); c.invalidContainerLoopError(nullptr, nullptr, ErrorPath{}); - c.invalidContainerError(nullptr, nullptr, nullptr, ErrorPath{}); + c.invalidContainerError(nullptr, nullptr, ErrorPath{}); c.invalidContainerReferenceError(nullptr, nullptr, ErrorPath{}); c.mismatchingContainerIteratorError(nullptr, nullptr, nullptr); c.mismatchingContainersError(nullptr, nullptr); diff --git a/lib/checkstl.h b/lib/checkstl.h index 60b9d4c7000..03a634f1ed1 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -187,7 +187,7 @@ class CPPCHECKLIB CheckStl : public Check { void sizeError(const Token* tok); void redundantIfRemoveError(const Token* tok); void invalidContainerLoopError(const Token* tok, const Token* loopTok, ErrorPath errorPath); - void invalidContainerError(const Token *tok, const Token * contTok, const ValueFlow::Value *val, ErrorPath errorPath); + void invalidContainerError(const Token *tok, const ValueFlow::Value *val, ErrorPath errorPath); void invalidContainerReferenceError(const Token* tok, const Token* contTok, ErrorPath errorPath); void uselessCallsReturnValueError(const Token* tok, const std::string& varname, const std::string& function); diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index a4cdfc5370a..1ba1aeb0b13 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1430,7 +1430,7 @@ class CPPCHECKLIB SymbolDatabase { /* returns the opening { if tok points to enum */ static const Token* isEnumDefinition(const Token* tok); - static void getErrorMessages(ErrorLogger &errorLogger); + static void getErrorMessages(ErrorLogger& /*errorLogger*/); // check if type has no side effects (no constructors and no members with constructors) /** @todo false negative: check constructors for side effects */ diff --git a/test/fixture.h b/test/fixture.h index 35239f0797c..a255c683d4c 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -286,7 +286,7 @@ class TestFixture : public ErrorLogger { std::ostringstream mOutput; std::ostringstream mErrout; - void reportOut(const std::string &outmsg, Color c = Color::Reset) override; + void reportOut(const std::string &outmsg, Color /*c*/ = Color::Reset) override; void reportErr(const ErrorMessage &msg) override; void reportMetric(const std::string &metric) override { diff --git a/test/testother.cpp b/test/testother.cpp index c6788a16f3a..f699090e831 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1792,7 +1792,7 @@ class TestOther : public TestFixture { void varScope39() { check("struct S {\n" // #12405 - " void f(const std::string&) const;\n" + " void f(const std::string& s) const;\n" " const int* g(std::string&) const;\n" "};\n" "void h(int);\n" @@ -3621,7 +3621,7 @@ class TestOther : public TestFixture { "class D\n" "{\n" "public:\n" - " explicit D(int&);\n" + " explicit D(int& i);\n" "\n" "private:\n" " C c;\n" @@ -3642,7 +3642,7 @@ class TestOther : public TestFixture { "class D\n" "{\n" "public:\n" - " explicit D(int&) noexcept;\n" + " explicit D(int& i) noexcept;\n" "\n" "private:\n" " C c;\n" @@ -3662,7 +3662,7 @@ class TestOther : public TestFixture { "class D\n" "{\n" "public:\n" - " explicit D(int&);\n" + " explicit D(int& i);\n" "\n" "private:\n" " C c;\n" @@ -3683,7 +3683,7 @@ class TestOther : public TestFixture { "class D\n" "{\n" "public:\n" - " explicit D(int&);\n" + " explicit D(int& i);\n" "\n" "private:\n" " C c;\n" @@ -3704,7 +3704,7 @@ class TestOther : public TestFixture { "class D\n" "{\n" "public:\n" - " explicit D(int&);\n" + " explicit D(int& i);\n" "\n" "private:\n" " C c;\n" @@ -6776,7 +6776,7 @@ class TestOther : public TestFixture { " AMethodObject(double, double, double);\n" "};\n" "struct S {\n" - " static void A(double, double, double);\n" + " static void A(double a1, double a2, double a3);\n" "};\n" "void S::A(double const a1, double const a2, double const a3) {\n" " AMethodObject(a1, a2, a3);\n" @@ -8013,7 +8013,7 @@ class TestOther : public TestFixture { "public:\n" " double getScale() const { return m_range * m_zoom; }\n" " void setZoom(double z) { m_zoom = z; }\n" - " void dostuff(int);\n" + " void dostuff(int x);\n" "private:\n" " double m_zoom;\n" " double m_range;\n" @@ -12769,6 +12769,16 @@ class TestOther : public TestFixture { "[test.cpp:7:15] -> [test.cpp:8:15]: (style, inconclusive) Function 'h' argument 1 names different: declaration 'a' definition 'b'. [funcArgNamesDifferent]\n", errout_str()); + check("void f(int a);\n" // #14632 + "void f(int) {}\n" + "void g(int);\n" + "void g(int b) {}\n" + "void h(int);\n" + "void h(int) {}\n"); + ASSERT_EQUALS( + "[test.cpp:1:12]: (style, inconclusive) Function 'f' argument 1 names different: declaration 'a' definition ''. [funcArgNamesDifferent]\n" + "[test.cpp:4:12]: (style, inconclusive) Function 'g' argument 1 names different: declaration '' definition 'b'. [funcArgNamesDifferent]\n", + errout_str()); } void funcArgOrderDifferent() {