Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,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;
}
Expand All @@ -1645,6 +1649,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);
Expand Down
10 changes: 9 additions & 1 deletion releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`

2 changes: 1 addition & 1 deletion test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TestFixture : public ErrorLogger {
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;
}
Expand Down