Fixed #5145 (False Positive: Variable 'A' hides enumerator with same name)
This commit is contained in:
parent
5f0cfa0ee4
commit
bcc8384a95
@ -7801,9 +7801,8 @@ void Tokenizer::simplifyEnum()
|
|||||||
tok3 = tok3->link(); // skip inner scopes
|
tok3 = tok3->link(); // skip inner scopes
|
||||||
else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) {
|
else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) {
|
||||||
const Token *prev = tok3->previous();
|
const Token *prev = tok3->previous();
|
||||||
if ((prev->isName() && !Token::Match(prev, "return|case|throw")) ||
|
if ((prev->isName() && !Token::Match(prev,"return|case|throw")) ||
|
||||||
prev->str() == "*" ||
|
Token::Match(prev, "&|* %type% =")) {
|
||||||
Token::Match(prev, "& %type% =")) {
|
|
||||||
// variable declaration?
|
// variable declaration?
|
||||||
shadowVars.insert(tok3->str());
|
shadowVars.insert(tok3->str());
|
||||||
if (inScope && _settings->isEnabled("style")) {
|
if (inScope && _settings->isEnabled("style")) {
|
||||||
|
@ -371,6 +371,7 @@ private:
|
|||||||
TEST_CASE(enum36); // ticket #4378
|
TEST_CASE(enum36); // ticket #4378
|
||||||
TEST_CASE(enum37); // ticket #4280 (shadow variable)
|
TEST_CASE(enum37); // ticket #4280 (shadow variable)
|
||||||
TEST_CASE(enum38); // ticket #4463 (when throwing enum id, don't warn about 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(enumscope1); // ticket #3949
|
||||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||||
|
|
||||||
@ -7452,6 +7453,12 @@ private:
|
|||||||
ASSERT_EQUALS("", errout.str());
|
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
|
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
||||||
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
||||||
"void bar() { int a = A; }";
|
"void bar() { int a = A; }";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user