diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index e2804f159..203ee3370 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -853,7 +853,7 @@ void CheckClass::initializationListUsage() if (Token::Match(tok, "%var% =") && tok->strAt(-1) != "*") { const Variable* var = tok->variable(); 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; bool allowed = true; diff --git a/test/testclass.cpp b/test/testclass.cpp index 39919d85a..f130cf0f0 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -5907,10 +5907,12 @@ private: } 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* 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());