From 02d8f691f85d3a6157c889237ad58294b0269606 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 22 Nov 2016 12:09:30 +0100 Subject: [PATCH] Fixed false positive: Do not show useInitializationList message for enums --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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());