Skip to content

Commit

Permalink
Refs #12913: Fix FN redundantCopyLocalConst with auto (#6584)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jul 12, 2024
1 parent c89574c commit d3f01ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@ void CheckOther::checkRedundantCopy()

for (const Variable* var : symbolDatabase->variableList()) {
if (!var || var->isReference() || var->isPointer() ||
(!var->type() && !var->isStlType()) || // bailout if var is of standard type, if it is a pointer or non-const
(!var->type() && !var->isStlType() && !(var->valueType() && var->valueType()->container)) || // bailout if var is of standard type, if it is a pointer or non-const
(!var->isConst() && isVariableChanged(var, *mSettings)))
continue;

Expand Down
10 changes: 10 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9046,6 +9046,16 @@ class TestOther : public TestFixture {
TODO_ASSERT_EQUALS("",
"[test.cpp:16] -> [test.cpp:18]: (style) The comparison 'c == m->get()' is always true because 'c' and 'm->get()' represent the same value.\n",
errout_str());

check("struct T {\n"
" std::string s;\n"
" const std::string& get() const { return s; }\n"
"};\n"
"void f(const T& t) {\n"
" const auto s = t.get();\n"
" if (s.empty()) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying.\n", errout_str());
}

void checkNegativeShift() {
Expand Down

0 comments on commit d3f01ab

Please sign in to comment.