Update constVariable IDs for references and pointers (#4904)

This commit is contained in:
Paul Fultz II 2023-04-07 13:14:53 -05:00 committed by GitHub
parent f52c00c3a7
commit 93b4de36cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -1628,6 +1628,10 @@ void CheckOther::constVariableError(const Variable *var, const Function *functio
if (!var) {
reportError(nullptr, Severity::style, "constParameter", "Parameter 'x' can be declared with const");
reportError(nullptr, Severity::style, "constVariable", "Variable 'x' can be declared with const");
reportError(nullptr, Severity::style, "constParameterReference", "Parameter 'x' can be declared with const");
reportError(nullptr, Severity::style, "constVariableReference", "Variable 'x' can be declared with const");
reportError(nullptr, Severity::style, "constParameterPointer", "Parameter 'x' can be declared with const");
reportError(nullptr, Severity::style, "constVariablePointer", "Variable 'x' can be declared with const");
reportError(nullptr, Severity::style, "constParameterCallback", "Parameter 'x' can be declared with const, however it seems that 'f' is a callback function.");
return;
}
@ -1644,6 +1648,10 @@ void CheckOther::constVariableError(const Variable *var, const Function *functio
errorPath.emplace_front(function->functionPointerUsage, "You might need to cast the function pointer here");
id += "Callback";
message += ". However it seems that '" + function->name() + "' is a callback function, if '$symbol' is declared with const you might also need to cast function pointer(s).";
} else if (var->isReference()) {
id += "Reference";
} else if (var->isPointer() && !var->isArray()) {
id += "Pointer";
}
reportError(errorPath, Severity::style, id.c_str(), message, CWE398, Certainty::normal);

View File

@ -4,4 +4,12 @@ release notes for cppcheck-2.11
- It is no longer necessary to run "--check-config" to get detailed "missingInclude" and "missingIncludeSystem" messages. They will always be issued in the regular analysis if "missingInclude" is enabled.
- "missingInclude" and "missingIncludeSystem" are reported with "-j" is > 1 and processes are used in the backend (default in non-Windows binaries)
- "missingInclude" and "missingIncludeSystem" will now cause the "--error-exitcode" to be applied
- "--enable=information" will no longer implicitly enable "missingInclude" starting with 2.16. Please enable it explicitly if you require it.
- "--enable=information" will no longer implicitly enable "missingInclude" starting with 2.16. Please enable it explicitly if you require it.
- The `constParameter` and `constVariable` checks have been split into 3 different IDs based on if the variable is a pointer, a reference, or local. The different IDs will allow users to suppress different const warning based on variable type.
- `constParameter`
- `constParameterReference`
- `constParameterPointer`
- `constVariable`
- `constVariableReference`
- `constVariablePointer`

View File

@ -4236,7 +4236,7 @@ void ignoredReturnValue_string_compare(std::string teststr, std::wstring testwst
testwstr.compare(L"wtest");
}
// cppcheck-suppress constParameter
// cppcheck-suppress constParameterReference
void ignoredReturnValue_container_access(std::string& s, std::string_view& sv, std::vector<int>& v)
{
// cppcheck-suppress ignoredReturnValue

View File

@ -114,7 +114,7 @@ protected:
static T& getCheck()
{
for (Check *check : Check::instances()) {
//cppcheck-suppress [constVariable, useStlAlgorithm] - TODO: fix constVariable FP
//cppcheck-suppress [constVariablePointer, useStlAlgorithm] - TODO: fix constVariable FP
if (T* c = dynamic_cast<T*>(check))
return *c;
}