Fixed false positive #5004

This commit is contained in:
PKEuS 2013-09-03 10:54:10 +02:00
parent 6b47ed414a
commit b36a887608
2 changed files with 7 additions and 1 deletions

View File

@ -774,7 +774,7 @@ void CheckClass::initializationListUsage()
}
if (!allowed)
continue;
if (!var->isPointer() && (var->type() || Token::Match(var->typeStartToken(), "std :: string|wstring !!::") || (Token::Match(var->typeStartToken(), "std :: %type% <") && !Token::simpleMatch(var->typeStartToken()->linkAt(3), "> ::"))))
if (!var->isPointer() && !var->isReference() && (var->type() || Token::Match(var->typeStartToken(), "std :: string|wstring !!::") || (Token::Match(var->typeStartToken(), "std :: %type% <") && !Token::simpleMatch(var->typeStartToken()->linkAt(3), "> ::"))))
suggestInitializationList(tok, tok->str());
}
}

View File

@ -5475,6 +5475,12 @@ private:
"};");
ASSERT_EQUALS("[test.cpp:3]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout.str());
checkInitializationListUsage("class Fred {\n"
" std::string& s;\n" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004)
" Fred(const std::string& s) : s(s_) { s = \"foo\"; }\n"
"};");
ASSERT_EQUALS("", errout.str());
checkInitializationListUsage("class Fred {\n"
" std::vector<int> v;\n"
" Fred() { v = unknown; }\n"