Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #12384 - removed misleading suggestion from passedByValue and iterateByValue messages #7205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 2 additions & 6 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,8 +1464,8 @@ void CheckOther::passedByValueError(const Variable* var, bool inconclusive, bool
std::string id = isRangeBasedFor ? "iterateByValue" : "passedByValue";
const std::string action = isRangeBasedFor ? "declared as": "passed by";
const std::string type = isRangeBasedFor ? "Range variable" : "Function parameter";
std::string msg = "$symbol:" + (var ? var->name() : "") + "\n" +
type + " '$symbol' should be " + action + " const reference.";
std::string msg = "$symbol:" + (var ? var->name() : "") + "\n";
msg += type + " '$symbol' is " + action + " value.";
ErrorPath errorPath;
if (var && var->scope() && var->scope()->function && var->scope()->function->functionPointerUsage) {
id += "Callback";
Expand All @@ -1474,10 +1474,6 @@ void CheckOther::passedByValueError(const Variable* var, bool inconclusive, bool
}
if (var)
errorPath.emplace_back(var->nameToken(), msg);
if (isRangeBasedFor)
msg += "\nVariable '$symbol' is used to iterate by value. It could be declared as a const reference which is usually faster and recommended in C++.";
else
msg += "\nParameter '$symbol' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.";
reportError(errorPath, Severity::performance, id.c_str(), msg, CWE398, inconclusive ? Certainty::inconclusive : Certainty::normal);
}

Expand Down
2 changes: 1 addition & 1 deletion samples/passedByValue_1/out.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
samples\passedByValue_1\bad.cpp:4:28: performance: Function parameter 's' should be passed by const reference. [passedByValue]
samples\passedByValue_1\bad.cpp:4:28: performance: Function parameter 's' is passed by value. [passedByValue]
explicit C(std::string s)
^
2 changes: 1 addition & 1 deletion samples/passedByValue_2/out.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
samples\passedByValue_2\bad.cpp:1:22: performance: Function parameter 's' should be passed by const reference. [passedByValue]
samples\passedByValue_2\bad.cpp:1:22: performance: Function parameter 's' is passed by value. [passedByValue]
bool foo(std::string s)
^
Loading
Loading