diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b2dd2a65d..62a21c401 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7801,9 +7801,8 @@ void Tokenizer::simplifyEnum() tok3 = tok3->link(); // skip inner scopes else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) { const Token *prev = tok3->previous(); - if ((prev->isName() && !Token::Match(prev, "return|case|throw")) || - prev->str() == "*" || - Token::Match(prev, "& %type% =")) { + if ((prev->isName() && !Token::Match(prev,"return|case|throw")) || + Token::Match(prev, "&|* %type% =")) { // variable declaration? shadowVars.insert(tok3->str()); if (inScope && _settings->isEnabled("style")) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index ea0acc2bc..70cce0ea3 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -371,6 +371,7 @@ private: TEST_CASE(enum36); // ticket #4378 TEST_CASE(enum37); // ticket #4280 (shadow variable) TEST_CASE(enum38); // ticket #4463 (when throwing enum id, don't warn about shadow variable) + TEST_CASE(enum39); // ticket #5145 (fp variable hides enum) TEST_CASE(enumscope1); // ticket #3949 TEST_CASE(duplicateDefinition); // ticket #3565 @@ -7452,6 +7453,12 @@ private: ASSERT_EQUALS("", errout.str()); } + void enum39() { // #5145 - fp variable hides enum + const char code[] = "enum { A }; void f() { int a = 1 * A; }"; + checkSimplifyEnum(code); + ASSERT_EQUALS("", errout.str()); + } + void enumscope1() { // #3949 - don't simplify enum from one function in another function const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n" "void bar() { int a = A; }";