Don't suggest using initialization list for static variables (#4332)

This commit is contained in:
PKEuS 2012-11-04 11:59:09 +01:00
parent e44ee280bc
commit b0c1c2c819
2 changed files with 7 additions and 1 deletions

View File

@ -657,7 +657,7 @@ void CheckClass::initializationListUsage()
break;
if (tok->varId() && Token::Match(tok, "%var% = %any%")) {
const Variable* var = symbolDatabase->getVariableFromVarId(tok->varId());
if (var && var->scope() == owner) {
if (var && var->scope() == owner && !var->isStatic()) {
bool allowed = true;
for (const Token* tok2 = tok->tokAt(2); tok2->str() != ";"; tok2 = tok2->next()) {
if (tok2->varId()) {

View File

@ -5399,6 +5399,12 @@ private:
" Fred() { a = foo(); }\n"
"};");
ASSERT_EQUALS("[test.cpp:3]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list.\n", errout.str());
checkInitializationListUsage("class Fred {\n" // #4332
" static std::string s;\n"
" Fred() { s = \"foo\"; }\n"
"};");
ASSERT_EQUALS("", errout.str());
}
// ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."