Skip to content

Commit 93b4de3

Browse files
authored
Update constVariable IDs for references and pointers (#4904)
1 parent f52c00c commit 93b4de3

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

lib/checkother.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,10 @@ void CheckOther::constVariableError(const Variable *var, const Function *functio
16281628
if (!var) {
16291629
reportError(nullptr, Severity::style, "constParameter", "Parameter 'x' can be declared with const");
16301630
reportError(nullptr, Severity::style, "constVariable", "Variable 'x' can be declared with const");
1631+
reportError(nullptr, Severity::style, "constParameterReference", "Parameter 'x' can be declared with const");
1632+
reportError(nullptr, Severity::style, "constVariableReference", "Variable 'x' can be declared with const");
1633+
reportError(nullptr, Severity::style, "constParameterPointer", "Parameter 'x' can be declared with const");
1634+
reportError(nullptr, Severity::style, "constVariablePointer", "Variable 'x' can be declared with const");
16311635
reportError(nullptr, Severity::style, "constParameterCallback", "Parameter 'x' can be declared with const, however it seems that 'f' is a callback function.");
16321636
return;
16331637
}
@@ -1644,6 +1648,10 @@ void CheckOther::constVariableError(const Variable *var, const Function *functio
16441648
errorPath.emplace_front(function->functionPointerUsage, "You might need to cast the function pointer here");
16451649
id += "Callback";
16461650
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).";
1651+
} else if (var->isReference()) {
1652+
id += "Reference";
1653+
} else if (var->isPointer() && !var->isArray()) {
1654+
id += "Pointer";
16471655
}
16481656

16491657
reportError(errorPath, Severity::style, id.c_str(), message, CWE398, Certainty::normal);

releasenotes.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ release notes for cppcheck-2.11
44
- 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.
55
- "missingInclude" and "missingIncludeSystem" are reported with "-j" is > 1 and processes are used in the backend (default in non-Windows binaries)
66
- "missingInclude" and "missingIncludeSystem" will now cause the "--error-exitcode" to be applied
7-
- "--enable=information" will no longer implicitly enable "missingInclude" starting with 2.16. Please enable it explicitly if you require it.
7+
- "--enable=information" will no longer implicitly enable "missingInclude" starting with 2.16. Please enable it explicitly if you require it.
8+
- 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.
9+
- `constParameter`
10+
- `constParameterReference`
11+
- `constParameterPointer`
12+
- `constVariable`
13+
- `constVariableReference`
14+
- `constVariablePointer`
15+

test/cfg/std.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,7 +4236,7 @@ void ignoredReturnValue_string_compare(std::string teststr, std::wstring testwst
42364236
testwstr.compare(L"wtest");
42374237
}
42384238

4239-
// cppcheck-suppress constParameter
4239+
// cppcheck-suppress constParameterReference
42404240
void ignoredReturnValue_container_access(std::string& s, std::string_view& sv, std::vector<int>& v)
42414241
{
42424242
// cppcheck-suppress ignoredReturnValue

test/fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class TestFixture : public ErrorLogger {
114114
static T& getCheck()
115115
{
116116
for (Check *check : Check::instances()) {
117-
//cppcheck-suppress [constVariable, useStlAlgorithm] - TODO: fix constVariable FP
117+
//cppcheck-suppress [constVariablePointer, useStlAlgorithm] - TODO: fix constVariable FP
118118
if (T* c = dynamic_cast<T*>(check))
119119
return *c;
120120
}

0 commit comments

Comments
 (0)