Show redundantCopyLocalConst for STL types (#4331)

This commit is contained in:
PKEuS 2014-03-27 11:15:17 +01:00
parent 379807a8ea
commit b23aebf2f0
2 changed files with 7 additions and 1 deletions

View File

@ -3259,7 +3259,7 @@ void CheckOther::checkRedundantCopy()
for (std::size_t i = 0; i < symbolDatabase->getVariableListSize(); 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;
const Token* startTok = var->nameToken();

View File

@ -6049,6 +6049,12 @@ private:
checkOther.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"
"const A& getA(){static A a;return a;}\n"
"int main()\n"