Update constVariable IDs for references and pointers (#4904)
This commit is contained in:
parent
f52c00c3a7
commit
93b4de36cd
|
@ -1628,6 +1628,10 @@ void CheckOther::constVariableError(const Variable *var, const Function *functio
|
||||||
if (!var) {
|
if (!var) {
|
||||||
reportError(nullptr, Severity::style, "constParameter", "Parameter 'x' can be declared with const");
|
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, "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.");
|
reportError(nullptr, Severity::style, "constParameterCallback", "Parameter 'x' can be declared with const, however it seems that 'f' is a callback function.");
|
||||||
return;
|
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");
|
errorPath.emplace_front(function->functionPointerUsage, "You might need to cast the function pointer here");
|
||||||
id += "Callback";
|
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).";
|
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);
|
reportError(errorPath, Severity::style, id.c_str(), message, CWE398, Certainty::normal);
|
||||||
|
|
|
@ -5,3 +5,11 @@ release notes for cppcheck-2.11
|
||||||
- "missingInclude" and "missingIncludeSystem" are reported with "-j" is > 1 and processes are used in the backend (default in non-Windows binaries)
|
- "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
|
- "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`
|
||||||
|
|
||||||
|
|
|
@ -4236,7 +4236,7 @@ void ignoredReturnValue_string_compare(std::string teststr, std::wstring testwst
|
||||||
testwstr.compare(L"wtest");
|
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)
|
void ignoredReturnValue_container_access(std::string& s, std::string_view& sv, std::vector<int>& v)
|
||||||
{
|
{
|
||||||
// cppcheck-suppress ignoredReturnValue
|
// cppcheck-suppress ignoredReturnValue
|
||||||
|
|
|
@ -114,7 +114,7 @@ protected:
|
||||||
static T& getCheck()
|
static T& getCheck()
|
||||||
{
|
{
|
||||||
for (Check *check : Check::instances()) {
|
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))
|
if (T* c = dynamic_cast<T*>(check))
|
||||||
return *c;
|
return *c;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue