Skip to content

Commit d3f01ab

Browse files
Refs #12913: Fix FN redundantCopyLocalConst with auto (#6584)
1 parent c89574c commit d3f01ab

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ void CheckOther::checkRedundantCopy()
29132913

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

test/testother.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9046,6 +9046,16 @@ class TestOther : public TestFixture {
90469046
TODO_ASSERT_EQUALS("",
90479047
"[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",
90489048
errout_str());
9049+
9050+
check("struct T {\n"
9051+
" std::string s;\n"
9052+
" const std::string& get() const { return s; }\n"
9053+
"};\n"
9054+
"void f(const T& t) {\n"
9055+
" const auto s = t.get();\n"
9056+
" if (s.empty()) {}\n"
9057+
"}\n");
9058+
ASSERT_EQUALS("[test.cpp:6]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying.\n", errout_str());
90499059
}
90509060

90519061
void checkNegativeShift() {

0 commit comments

Comments
 (0)