Fixed false positive: Do not show useInitializationList message for enums

This commit is contained in:
PKEuS 2016-11-22 12:09:30 +01:00
parent aff84daff3
commit 02d8f691f8
2 changed files with 5 additions and 3 deletions

View File

@ -853,7 +853,7 @@ void CheckClass::initializationListUsage()
if (Token::Match(tok, "%var% =") && tok->strAt(-1) != "*") { if (Token::Match(tok, "%var% =") && tok->strAt(-1) != "*") {
const Variable* var = tok->variable(); const Variable* var = tok->variable();
if (var && var->scope() == owner && !var->isStatic()) { if (var && var->scope() == owner && !var->isStatic()) {
if (var->isPointer() || var->isReference() || (!var->type() && !var->isStlStringType() && !(Token::Match(var->typeStartToken(), "std :: %type% <") && !Token::simpleMatch(var->typeStartToken()->linkAt(3), "> ::")))) if (var->isPointer() || var->isReference() || var->isEnumType() || (!var->type() && !var->isStlStringType() && !(Token::Match(var->typeStartToken(), "std :: %type% <") && !Token::simpleMatch(var->typeStartToken()->linkAt(3), "> ::"))))
continue; continue;
bool allowed = true; bool allowed = true;

View File

@ -5907,10 +5907,12 @@ private:
} }
void initializerListUsage() { void initializerListUsage() {
checkInitializationListUsage("class Fred {\n" checkInitializationListUsage("enum Enum { C = 0 };\n"
"class Fred {\n"
" int a;\n" // No message for builtin types: No performance gain " int a;\n" // No message for builtin types: No performance gain
" int* b;\n" // No message for pointers: No performance gain " int* b;\n" // No message for pointers: No performance gain
" Fred() { a = 0; b = 0; }\n" " Enum c;\n" // No message for enums: No performance gain
" Fred() { a = 0; b = 0; c = C; }\n"
"};"); "};");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());