Fixed #4280 (Tokenizer::simplifyEnum: don't simplify shadow variables)
This commit is contained in:
parent
e90a3c179f
commit
8954cc0984
|
@ -7432,6 +7432,22 @@ void Tokenizer::simplifyEnum()
|
|||
// Create a copy of the shadow ids for the inner scope
|
||||
if (!shadowId.empty())
|
||||
shadowId.push(shadowId.top());
|
||||
|
||||
if (Token::simpleMatch(tok2->previous(), ") {") || Token::simpleMatch(tok2->tokAt(-2), ") const {")) {
|
||||
std::set<std::string> shadowArg;
|
||||
for (const Token* arg = tok2; arg && arg->str() != "("; arg = arg->previous()) {
|
||||
if (Token::Match(arg, "%type% [,)]") && enumValues.find(arg->str()) != enumValues.end()) {
|
||||
shadowArg.insert(arg->str());
|
||||
}
|
||||
}
|
||||
if (!shadowArg.empty()) {
|
||||
if (shadowId.empty())
|
||||
shadowId.push(shadowArg);
|
||||
else
|
||||
shadowId.top().insert(shadowArg.begin(), shadowArg.end());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Function head
|
||||
} else if (Token::Match(tok2, "%var% (")) {
|
||||
|
|
|
@ -360,6 +360,7 @@ private:
|
|||
TEST_CASE(enum34); // ticket #4141 (division by zero)
|
||||
TEST_CASE(enum35); // ticket #3953 (avoid simplification of type)
|
||||
TEST_CASE(enum36); // ticket #4378
|
||||
TEST_CASE(enum37); // ticket #4280 (shadow variable)
|
||||
TEST_CASE(enumscope1); // ticket #3949
|
||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||
|
||||
|
@ -7333,6 +7334,11 @@ private:
|
|||
ASSERT_EQUALS("struct X { X ( int ) { int y ; y = ( int ) 1 ; } } ;", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enum37() { // #4280
|
||||
const char code[] = "enum { a, b }; void f(int a) { return a + 1; }";
|
||||
ASSERT_EQUALS("void f ( int a ) { return a + 1 ; }", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
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; }";
|
||||
|
|
Loading…
Reference in New Issue