From bb67f10e39e6aec2b0708b27f845e7983cd3223e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:36:24 +0100 Subject: [PATCH 01/22] Update checkclass.cpp --- lib/checkclass.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 39562d9e847..fb7220a20fa 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1322,7 +1322,7 @@ void CheckClass::privateFunctions() bool used = checkFunctionUsage(pf, scope); // Usage in this class // Check in friend classes const std::vector& friendList = scope->definedType->friendList; - for (std::size_t i = 0; i < friendList.size() && !used; i++) { + for (int i = 0; i < friendList.size() && !used; i++) { if (friendList[i].type) used = checkFunctionUsage(pf, friendList[i].type->classScope); else @@ -2174,7 +2174,8 @@ void CheckClass::checkConst() } // check if base class function is virtual - if (!scope->definedType->derivedFrom.empty() && func.isImplicitlyVirtual(true)) + bool foundAllBaseClasses = true; + if (!scope->definedType->derivedFrom.empty() && func.isImplicitlyVirtual(true, &foundAllBaseClasses) && foundAllBaseClasses) continue; MemberAccess memberAccessed = MemberAccess::NONE; @@ -2202,9 +2203,9 @@ void CheckClass::checkConst() functionName += "]"; if (func.isInline()) - checkConstError(func.token, classname, functionName, suggestStatic); + checkConstError(func.token, classname, functionName, suggestStatic, foundAllBaseClasses); else // not inline - checkConstError2(func.token, func.tokenDef, classname, functionName, suggestStatic); + checkConstError2(func.token, func.tokenDef, classname, functionName, suggestStatic, foundAllBaseClasses); } } } @@ -2611,35 +2612,41 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member return true; } -void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname, bool suggestStatic) +void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname, bool suggestStatic, bool foundAllBaseClasses) { - checkConstError2(tok, nullptr, classname, funcname, suggestStatic); + checkConstError2(tok, nullptr, classname, funcname, suggestStatic, foundAllBaseClasses); } -void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic) +void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic, bool foundAllBaseClasses) { std::list toks{ tok1 }; if (tok2) toks.push_back(tok2); - if (!suggestStatic) + if (!suggestStatic) { + const std::string msg = foundAllBaseClasses ? + "Technically the member function '$symbol' can be const.\nThe member function '$symbol' can be made a const " : + "Either there is a missing 'override', or the member function '$symbol' can be const.\nUnless it overrides a base class member, the member function '$symbol' can be made a const "; reportError(toks, Severity::style, "functionConst", "$symbol:" + classname + "::" + funcname +"\n" - "Technically the member function '$symbol' can be const.\n" - "The member function '$symbol' can be made a const " + + msg + "function. Making this function 'const' should not cause compiler errors. " "Even though the function can be made const function technically it may not make " "sense conceptually. Think about your design and the task of the function first - is " "it a function that must not change object internal state?", CWE398, Certainty::inconclusive); - else + } + else { + const std::string msg = foundAllBaseClasses ? + "Technically the member function '$symbol' can be static (but you may consider moving to unnamed namespace).\nThe member function '$symbol' can be made a static " : + "Either there is a missing 'override', or the member function '$symbol' can be static.\nUnless it overrides a base class member, the member function '$symbol' can be made a static "; reportError(toks, Severity::performance, "functionStatic", "$symbol:" + classname + "::" + funcname +"\n" - "Technically the member function '$symbol' can be static (but you may consider moving to unnamed namespace).\n" - "The member function '$symbol' can be made a static " + + msg + "function. Making a function static can bring a performance benefit since no 'this' instance is " "passed to the function. This change should not cause compiler errors but it does not " "necessarily make sense conceptually. Think about your design and the task of the function first - " "is it a function that must not access members of class instances? And maybe it is more appropriate " "to move this function to an unnamed namespace.", CWE398, Certainty::inconclusive); + } } //--------------------------------------------------------------------------- @@ -2715,7 +2722,7 @@ void CheckClass::initializerListOrder() } } - for (std::size_t j = 0; j < vars.size(); j++) { + for (int j = 0; j < vars.size(); j++) { // check for use of uninitialized arguments for (const auto& arg : vars[j].initArgs) if (vars[j].var->index() < arg->index()) From 73be594225bfc49bd217a974622c85adefdbd86c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:37:05 +0100 Subject: [PATCH 02/22] Update checkclass.h --- lib/checkclass.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.h b/lib/checkclass.h index 6cf0fb32f8b..2ec7fc1abe4 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -202,8 +202,8 @@ class CPPCHECKLIB CheckClass : public Check { void operatorEqShouldBeLeftUnimplementedError(const Token *tok); void operatorEqMissingReturnStatementError(const Token *tok, bool error); void operatorEqToSelfError(const Token *tok); - void checkConstError(const Token *tok, const std::string &classname, const std::string &funcname, bool suggestStatic); - void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic); + void checkConstError(const Token *tok, const std::string &classname, const std::string &funcname, bool suggestStatic, bool foundAllBaseClasses = true); + void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic, bool foundAllBaseClasses = true); void initializerListError(const Token *tok1,const Token *tok2, const std::string & classname, const std::string &varname, const std::string& argname = {}); void suggestInitializationList(const Token *tok, const std::string& varname); void selfInitializationError(const Token* tok, const std::string& varname); From 3ac9fec65fec15f22853c1e4d73ba3f6f2404b90 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:37:38 +0100 Subject: [PATCH 03/22] Update symboldatabase.h --- lib/symboldatabase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index bba22b78b3f..64c53ed15ff 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -778,7 +778,7 @@ class CPPCHECKLIB Function { void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope); /** @brief check if this function is virtual in the base classes */ - bool isImplicitlyVirtual(bool defaultVal = false) const; + bool isImplicitlyVirtual(bool defaultVal = false, bool* pFoundAllBaseClasses = nullptr) const; std::vector getOverloadedFunctions() const; From 697377eab91c61af1473cbf4e65cd9c016a65bb4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:37:56 +0100 Subject: [PATCH 04/22] Update symboldatabase.cpp --- lib/symboldatabase.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b2694508624..f12747aecc4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1039,7 +1039,7 @@ void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() for (Scope& scope : scopeList) { // add all variables for (Variable& var: scope.varlist) { - const int varId = var.declarationId(); + const unsigned int varId = var.declarationId(); if (varId) mVariableList[varId] = &var; // fix up variables without type @@ -1055,7 +1055,7 @@ void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() for (Variable& arg: func.argumentList) { // check for named parameters if (arg.nameToken() && arg.declarationId()) { - const int declarationId = arg.declarationId(); + const unsigned int declarationId = arg.declarationId(); mVariableList[declarationId] = &arg; // fix up parameters without type if (!arg.type() && !arg.typeStartToken()->isStandardType()) { @@ -2117,7 +2117,7 @@ namespace { { if (const Scope* scope = var->nameToken()->scope()) { auto it = std::find_if(scope->functionList.begin(), scope->functionList.end(), [&](const Function& function) { - for (nonneg int arg = 0; arg < function.argCount(); ++arg) { + for (std::size_t arg = 0; arg < function.argCount(); ++arg) { if (var == function.getArgumentVar(arg)) return true; } @@ -3011,7 +3011,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se // remove class name else if (arg_path_length > 2 && first->strAt(1) != second->strAt(1)) { std::string short_path = path; - int short_path_length = arg_path_length; + unsigned int short_path_length = arg_path_length; // remove last " :: " short_path.resize(short_path.size() - 4); @@ -3034,7 +3034,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se param = std::move(short_path); if (Token::simpleMatch(second->next(), param.c_str(), param.size())) { - second = second->tokAt(short_path_length); + second = second->tokAt(int(short_path_length)); arg_path_length = 0; } } @@ -4574,13 +4574,15 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s } } -bool Function::isImplicitlyVirtual(bool defaultVal) const +bool Function::isImplicitlyVirtual(bool defaultVal, bool* pFoundAllBaseClasses) const { if (hasVirtualSpecifier() || hasOverrideSpecifier() || hasFinalSpecifier()) return true; bool foundAllBaseClasses = true; if (getOverriddenFunction(&foundAllBaseClasses)) //If it overrides a base class's method then it's virtual return true; + if (pFoundAllBaseClasses) + *pFoundAllBaseClasses = foundAllBaseClasses; if (foundAllBaseClasses) //If we've seen all the base classes and none of the above were true then it must not be virtual return false; return defaultVal; //If we can't see all the bases classes then we can't say conclusively @@ -5961,7 +5963,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen // Prioritize matches in derived scopes for (const auto& fb : { fallback1Func, fallback2Func }) { const Function* ret = nullptr; - for (std::size_t i = 0; i < fb.size(); ++i) { + for (int i = 0; i < fb.size(); ++i) { if (std::find(matches.cbegin(), matches.cend(), fb[i]) == matches.cend()) continue; if (this == fb[i]->nestedIn) { @@ -7144,7 +7146,7 @@ static const Token* parsedecl(const Token* type, if (settings.debugnormal || settings.debugwarnings) valuetype->setDebugPath(type, loc); const Token * const previousType = type; - const int pointer0 = valuetype->pointer; + const unsigned int pointer0 = valuetype->pointer; while (Token::Match(type->previous(), "%name%") && !endsWith(type->strAt(-1), ':')) type = type->previous(); valuetype->sign = ValueType::Sign::UNKNOWN_SIGN; @@ -7477,9 +7479,9 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } else if (tok->isBoolean()) { setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0U)); } else if (tok->tokType() == Token::eChar || tok->tokType() == Token::eString) { - nonneg int const pointer = tok->tokType() == Token::eChar ? 0 : 1; - nonneg int const constness = tok->tokType() == Token::eChar ? 0 : 1; - nonneg int const volatileness = 0; + nonneg int const pointer = tok->tokType() == Token::eChar ? 0U : 1U; + nonneg int const constness = tok->tokType() == Token::eChar ? 0U : 1U; + nonneg int const volatileness = 0U; ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, pointer, constness, volatileness); if (tok->isCpp() && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) { From 51659a530464b85832aee257df0a0dfe90495554 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:38:20 +0100 Subject: [PATCH 05/22] Update testclass.cpp --- test/testclass.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index 64913601b65..0eb1a3cf4e2 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -186,6 +186,7 @@ class TestClass : public TestFixture { TEST_CASE(const92); TEST_CASE(const93); TEST_CASE(const94); + TEST_CASE(const95); TEST_CASE(const_handleDefaultParameters); TEST_CASE(const_passThisToMemberOfOtherClass); @@ -4855,7 +4856,7 @@ class TestClass : public TestFixture { " UnknownScope::x = x_;\n" " }\n" "};"); - ASSERT_EQUALS("", errout_str()); + ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Either there is a missing 'override', or the member function 'AA::vSetXPos' can be static.\n", errout_str()); checkConst("class AA {\n" "public:\n" @@ -5040,7 +5041,7 @@ class TestClass : public TestFixture { "public:\n" " void f(){}\n" "};"); - ASSERT_EQUALS("", errout_str()); + ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Either there is a missing 'override', or the member function 'derived::f' can be static.\n", errout_str()); } void const34() { // ticket #1964 @@ -5826,7 +5827,9 @@ class TestClass : public TestFixture { " inherited::set(inherited::Key(key));\n" " }\n" "};\n", nullptr, false); - ASSERT_EQUALS("", errout_str()); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static.\n" + "[test.cpp:2]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::InitializeFileReader' can be static.\n", + errout_str()); } void const62() { @@ -6705,6 +6708,15 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void const95() { // #13282 + checkConst("struct S : B {\n" + " bool f() { return b; }\n" + " bool g() override { return b; }\n" + " bool b;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const.\n", errout_str()); + } + void const_handleDefaultParameters() { checkConst("struct Foo {\n" " void foo1(int i, int j = 0) {\n" From 262f6752c771824b917fcf11bedcdbae82ad52f4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:43:29 +0100 Subject: [PATCH 06/22] Update symboldatabase.cpp --- lib/symboldatabase.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index f12747aecc4..0bb7b789dc2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1039,7 +1039,7 @@ void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() for (Scope& scope : scopeList) { // add all variables for (Variable& var: scope.varlist) { - const unsigned int varId = var.declarationId(); + const int varId = var.declarationId(); if (varId) mVariableList[varId] = &var; // fix up variables without type @@ -1055,7 +1055,7 @@ void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() for (Variable& arg: func.argumentList) { // check for named parameters if (arg.nameToken() && arg.declarationId()) { - const unsigned int declarationId = arg.declarationId(); + const int declarationId = arg.declarationId(); mVariableList[declarationId] = &arg; // fix up parameters without type if (!arg.type() && !arg.typeStartToken()->isStandardType()) { @@ -2117,7 +2117,7 @@ namespace { { if (const Scope* scope = var->nameToken()->scope()) { auto it = std::find_if(scope->functionList.begin(), scope->functionList.end(), [&](const Function& function) { - for (std::size_t arg = 0; arg < function.argCount(); ++arg) { + for (nonneg int arg = 0; arg < function.argCount(); ++arg) { if (var == function.getArgumentVar(arg)) return true; } @@ -3011,7 +3011,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se // remove class name else if (arg_path_length > 2 && first->strAt(1) != second->strAt(1)) { std::string short_path = path; - unsigned int short_path_length = arg_path_length; + int short_path_length = arg_path_length; // remove last " :: " short_path.resize(short_path.size() - 4); @@ -3034,7 +3034,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se param = std::move(short_path); if (Token::simpleMatch(second->next(), param.c_str(), param.size())) { - second = second->tokAt(int(short_path_length)); + second = second->tokAt(short_path_length); arg_path_length = 0; } } @@ -5963,7 +5963,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen // Prioritize matches in derived scopes for (const auto& fb : { fallback1Func, fallback2Func }) { const Function* ret = nullptr; - for (int i = 0; i < fb.size(); ++i) { + for (std::size_t i = 0; i < fb.size(); ++i) { if (std::find(matches.cbegin(), matches.cend(), fb[i]) == matches.cend()) continue; if (this == fb[i]->nestedIn) { @@ -7146,7 +7146,7 @@ static const Token* parsedecl(const Token* type, if (settings.debugnormal || settings.debugwarnings) valuetype->setDebugPath(type, loc); const Token * const previousType = type; - const unsigned int pointer0 = valuetype->pointer; + const int pointer0 = valuetype->pointer; while (Token::Match(type->previous(), "%name%") && !endsWith(type->strAt(-1), ':')) type = type->previous(); valuetype->sign = ValueType::Sign::UNKNOWN_SIGN; @@ -7479,9 +7479,9 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } else if (tok->isBoolean()) { setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0U)); } else if (tok->tokType() == Token::eChar || tok->tokType() == Token::eString) { - nonneg int const pointer = tok->tokType() == Token::eChar ? 0U : 1U; - nonneg int const constness = tok->tokType() == Token::eChar ? 0U : 1U; - nonneg int const volatileness = 0U; + nonneg int const pointer = tok->tokType() == Token::eChar ? 0 : 1; + nonneg int const constness = tok->tokType() == Token::eChar ? 0 : 1; + nonneg int const volatileness = 0; ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, pointer, constness, volatileness); if (tok->isCpp() && mSettings.standards.cpp >= Standards::CPP20 && tok->isUtf8()) { From d5008b6d362fee30beb2fc6f746d18efd543ab03 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:44:02 +0100 Subject: [PATCH 07/22] Update checkclass.cpp --- lib/checkclass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index fb7220a20fa..b7f74e59d2b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1322,7 +1322,7 @@ void CheckClass::privateFunctions() bool used = checkFunctionUsage(pf, scope); // Usage in this class // Check in friend classes const std::vector& friendList = scope->definedType->friendList; - for (int i = 0; i < friendList.size() && !used; i++) { + for (std::size_t i = 0; i < friendList.size() && !used; i++) { if (friendList[i].type) used = checkFunctionUsage(pf, friendList[i].type->classScope); else @@ -2722,7 +2722,7 @@ void CheckClass::initializerListOrder() } } - for (int j = 0; j < vars.size(); j++) { + for (std::size_t j = 0; j < vars.size(); j++) { // check for use of uninitialized arguments for (const auto& arg : vars[j].initArgs) if (vars[j].var->index() < arg->index()) From 69320512b6b3d92524f425ef9af66731f0e23142 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:06:37 +0100 Subject: [PATCH 08/22] Update qt.cpp --- test/cfg/qt.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index f00c15c7696..e77036a4636 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -665,6 +665,7 @@ namespace { class Fred : public QObject { Q_OBJECT private slots: + // cppcheck-suppress functionStatic void foo(); }; void Fred::foo() {} @@ -726,6 +727,7 @@ namespace { ~MyObject1() {} public slots: signals: + // cppcheck-suppress functionStatic void test() {} }; From cb5723a695ff78008dd9b23460b3e1b461a29ccf Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:16:22 +0100 Subject: [PATCH 09/22] Update checkclass.cpp --- lib/checkclass.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index b7f74e59d2b..788e508a4b2 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2280,9 +2280,12 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const // not found in this class if (!scope->definedType->derivedFrom.empty()) { // check each base class + bool foundAllBaseClasses = true; for (const Type::BaseInfo & i : scope->definedType->derivedFrom) { // find the base class const Type *derivedFrom = i.type; + if (!derivedFrom) + foundAllBaseClasses = false; // find the function in the base class if (derivedFrom && derivedFrom->classScope && derivedFrom->classScope != scope) { @@ -2290,6 +2293,8 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const return true; } } + if (!foundAllBaseClasses) + return true; } return false; @@ -2624,8 +2629,8 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st toks.push_back(tok2); if (!suggestStatic) { const std::string msg = foundAllBaseClasses ? - "Technically the member function '$symbol' can be const.\nThe member function '$symbol' can be made a const " : - "Either there is a missing 'override', or the member function '$symbol' can be const.\nUnless it overrides a base class member, the member function '$symbol' can be made a const "; + "Technically the member function '$symbol' can be const.\nThe member function '$symbol' can be made a const " : + "Either there is a missing 'override', or the member function '$symbol' can be const.\nUnless it overrides a base class member, the member function '$symbol' can be made a const "; reportError(toks, Severity::style, "functionConst", "$symbol:" + classname + "::" + funcname +"\n" + msg + @@ -2636,8 +2641,8 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st } else { const std::string msg = foundAllBaseClasses ? - "Technically the member function '$symbol' can be static (but you may consider moving to unnamed namespace).\nThe member function '$symbol' can be made a static " : - "Either there is a missing 'override', or the member function '$symbol' can be static.\nUnless it overrides a base class member, the member function '$symbol' can be made a static "; + "Technically the member function '$symbol' can be static (but you may consider moving to unnamed namespace).\nThe member function '$symbol' can be made a static " : + "Either there is a missing 'override', or the member function '$symbol' can be static.\nUnless it overrides a base class member, the member function '$symbol' can be made a static "; reportError(toks, Severity::performance, "functionStatic", "$symbol:" + classname + "::" + funcname +"\n" + msg + From da356d453231bbd63549c51cfd18899f1cab450f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:24:27 +0100 Subject: [PATCH 10/22] Update testclass.cpp --- test/testclass.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index 0eb1a3cf4e2..71c0e14d5a5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -4856,7 +4856,7 @@ class TestClass : public TestFixture { " UnknownScope::x = x_;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Either there is a missing 'override', or the member function 'AA::vSetXPos' can be static.\n", errout_str()); + ASSERT_EQUALS("", errout_str()); checkConst("class AA {\n" "public:\n" @@ -5827,8 +5827,7 @@ class TestClass : public TestFixture { " inherited::set(inherited::Key(key));\n" " }\n" "};\n", nullptr, false); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static.\n" - "[test.cpp:2]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::InitializeFileReader' can be static.\n", + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (performance, inconclusive) Either there is a missing 'override', or the member function 'MixerParticipant::GetAudioFrame' can be static.\n", errout_str()); } @@ -6676,8 +6675,6 @@ class TestClass : public TestFixture { "struct S<0> {};\n" "struct D : S<150> {};\n"); // don't hang - // we are not interested in the output - just consume it - ignore_errout(); } void const93() { // #12162 From 08db401b694b7baa722fc0aa65f4b6795f95bd53 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:36:22 +0100 Subject: [PATCH 11/22] Update codeeditstylecontrols.h --- gui/codeeditstylecontrols.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/codeeditstylecontrols.h b/gui/codeeditstylecontrols.h index dbc7aedeed1..e40746a77a3 100644 --- a/gui/codeeditstylecontrols.h +++ b/gui/codeeditstylecontrols.h @@ -36,7 +36,7 @@ class SelectColorButton : public QPushButton { explicit SelectColorButton(QWidget* parent); void setColor(const QColor& color); - const QColor& getColor(); + const QColor& getColor() const; signals: // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code @@ -57,7 +57,7 @@ class SelectFontWeightCombo : public QComboBox { explicit SelectFontWeightCombo(QWidget* parent); void setWeight(QFont::Weight weight); - const QFont::Weight& getWeight(); + const QFont::Weight& getWeight() const; signals: // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code From 48af0b772e451c86dd9a9287c80775987f357b59 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:37:03 +0100 Subject: [PATCH 12/22] Update codeeditstylecontrols.cpp --- gui/codeeditstylecontrols.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/codeeditstylecontrols.cpp b/gui/codeeditstylecontrols.cpp index 99121c10afd..1623d75a68a 100644 --- a/gui/codeeditstylecontrols.cpp +++ b/gui/codeeditstylecontrols.cpp @@ -65,7 +65,7 @@ void SelectColorButton::setColor(const QColor& color) } // cppcheck-suppress unusedFunction -const QColor& SelectColorButton::getColor() +const QColor& SelectColorButton::getColor() const { return mColor; } @@ -122,7 +122,7 @@ void SelectFontWeightCombo::setWeight(QFont::Weight weight) } // cppcheck-suppress unusedFunction -const QFont::Weight& SelectFontWeightCombo::getWeight() +const QFont::Weight& SelectFontWeightCombo::getWeight() const { return mWeight; } From acc3c79c1185f8d37c6909ecd75b22343d2eeb59 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:37:52 +0100 Subject: [PATCH 13/22] Update codeeditstyledialog.h --- gui/codeeditstyledialog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/codeeditstyledialog.h b/gui/codeeditstyledialog.h index bd7a70ac2a5..92b31efd46a 100644 --- a/gui/codeeditstyledialog.h +++ b/gui/codeeditstyledialog.h @@ -43,7 +43,7 @@ class StyleEditDialog : public QDialog { explicit StyleEditDialog(const CodeEditorStyle& newStyle, QWidget *parent = nullptr); - CodeEditorStyle getStyle(); + CodeEditorStyle getStyle() const; private: void updateControls(); From beed1852c2281de5c033ce2c1fa3cc92aa446a0e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:38:14 +0100 Subject: [PATCH 14/22] Update codeeditstyledialog.cpp --- gui/codeeditstyledialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/codeeditstyledialog.cpp b/gui/codeeditstyledialog.cpp index b7b782ffc39..33bd9ff7e1a 100644 --- a/gui/codeeditstyledialog.cpp +++ b/gui/codeeditstyledialog.cpp @@ -235,7 +235,7 @@ void StyleEditDialog::updateStyle() mSampleEditor->setStyle(mStyleOutgoing); } -CodeEditorStyle StyleEditDialog::getStyle() +CodeEditorStyle StyleEditDialog::getStyle() const { return mStyleOutgoing; } From f051a2fa41529e30547d0d371742dc38ce78cad9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:38:55 +0100 Subject: [PATCH 15/22] Update resultstree.h --- gui/resultstree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/resultstree.h b/gui/resultstree.h index ff5af1a9d09..370a2c0f256 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -137,7 +137,7 @@ class ResultsTree : public QTreeView { * @return Directory containing source files */ - const QString& getCheckDirectory(); + const QString& getCheckDirectory() const; /** * @brief Check if there are any visible results in view. From 8caa410b4eb38d6a542096b87e6163f1b4dee125 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:39:38 +0100 Subject: [PATCH 16/22] Update resultstree.cpp --- gui/resultstree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index c0e07969333..4e3001a6877 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -1524,7 +1524,7 @@ void ResultsTree::setCheckDirectory(const QString &dir) } -const QString& ResultsTree::getCheckDirectory() +const QString& ResultsTree::getCheckDirectory() const { return mCheckPath; } From 3a9041f2464d1724dcd7c09e59be4143284c6a31 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:40:00 +0100 Subject: [PATCH 17/22] Update resultsview.h --- gui/resultsview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/resultsview.h b/gui/resultsview.h index 8dc37b24591..404d37b690c 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -331,7 +331,7 @@ public slots: * @brief Slot printing the current report to the printer. * @param printer The printer used for printing the report. */ - void print(QPrinter* printer); + void print(QPrinter* printer) const; /** * @brief Slot opening a print preview dialog From 9e547857b3cfb07c2183399eabd6e7e13aae6538 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:40:28 +0100 Subject: [PATCH 18/22] Update resultsview.cpp --- gui/resultsview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 709dc22b8d2..8fd448806c4 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -262,7 +262,7 @@ void ResultsView::printPreview() dialog.exec(); } -void ResultsView::print(QPrinter* printer) +void ResultsView::print(QPrinter* printer) const { if (!hasResults()) { QMessageBox msgBox; From 5deac562ea050eb57fc99e365992c89ee813cecf Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:57:50 +0100 Subject: [PATCH 19/22] Update resultsview.h --- gui/resultsview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/resultsview.h b/gui/resultsview.h index 404d37b690c..771f04488ff 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -139,7 +139,7 @@ class ResultsView : public QWidget { * @return Directory containing source files */ - QString getCheckDirectory(); + QString getCheckDirectory() const; /** * Set settings used in checking From 37c93ca6685bfe59bd65fb2b98dfa010840c978f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:58:12 +0100 Subject: [PATCH 20/22] Update resultsview.cpp --- gui/resultsview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 8fd448806c4..e76a427a5ee 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -300,7 +300,7 @@ void ResultsView::setCheckDirectory(const QString &dir) mUI->mTree->setCheckDirectory(dir); } -QString ResultsView::getCheckDirectory() +QString ResultsView::getCheckDirectory() const { return mUI->mTree->getCheckDirectory(); } From e5d8304194b2d2996aa2d224a3461a6584ca59a1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:34:08 +0100 Subject: [PATCH 21/22] Update qt.cfg --- cfg/qt.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/qt.cfg b/cfg/qt.cfg index 15acfb0c6af..9b785150f37 100644 --- a/cfg/qt.cfg +++ b/cfg/qt.cfg @@ -5359,7 +5359,7 @@ - + From 295b44d544f3b857137e8833e0b62744462d5553 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:05:24 +0100 Subject: [PATCH 22/22] Update qt.cfg --- cfg/qt.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/qt.cfg b/cfg/qt.cfg index 9b785150f37..83f35d617a5 100644 --- a/cfg/qt.cfg +++ b/cfg/qt.cfg @@ -5359,7 +5359,7 @@ - +