Show redundantCopyLocalConst for STL types (#4331)
This commit is contained in:
parent
379807a8ea
commit
b23aebf2f0
|
@ -3259,7 +3259,7 @@ void CheckOther::checkRedundantCopy()
|
||||||
for (std::size_t i = 0; i < symbolDatabase->getVariableListSize(); i++) {
|
for (std::size_t i = 0; i < symbolDatabase->getVariableListSize(); i++) {
|
||||||
const Variable* var = symbolDatabase->getVariableFromVarId(i);
|
const Variable* var = symbolDatabase->getVariableFromVarId(i);
|
||||||
|
|
||||||
if (!var || var->isReference() || !var->isConst() || var->isPointer() || !var->type()) // bailout if var is of standard type, if it is a pointer or non-const
|
if (!var || var->isReference() || !var->isConst() || var->isPointer() || (!var->type() && !var->isStlType())) // bailout if var is of standard type, if it is a pointer or non-const
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Token* startTok = var->nameToken();
|
const Token* startTok = var->nameToken();
|
||||||
|
|
|
@ -6049,6 +6049,12 @@ private:
|
||||||
checkOther.checkRedundantCopy();
|
checkOther.checkRedundantCopy();
|
||||||
}
|
}
|
||||||
void checkRedundantCopy() {
|
void checkRedundantCopy() {
|
||||||
|
check_redundant_copy("const std::string& getA(){static std::string a;return a;}\n"
|
||||||
|
"void foo() {\n"
|
||||||
|
" const std::string a = getA();\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (performance) Use const reference for 'a' to avoid unnecessary data copying.\n", errout.str());
|
||||||
|
|
||||||
check_redundant_copy("class A{public:A(){}};\n"
|
check_redundant_copy("class A{public:A(){}};\n"
|
||||||
"const A& getA(){static A a;return a;}\n"
|
"const A& getA(){static A a;return a;}\n"
|
||||||
"int main()\n"
|
"int main()\n"
|
||||||
|
|
Loading…
Reference in New Issue