fix #2745 (Enum vs local variable - conflict)
This commit is contained in:
parent
670741271e
commit
3c415e7833
|
@ -7800,7 +7800,8 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name)
|
|||
// look backwards
|
||||
if (tok->previous()->str() == "enum" ||
|
||||
(Token::Match(tok->previous(), "%type%") &&
|
||||
tok->previous()->str() != "return"))
|
||||
tok->previous()->str() != "return") ||
|
||||
Token::Match(tok->tokAt(-2), "%type% &|*"))
|
||||
{
|
||||
duplicateEnumError(*tokPtr, name, "Function parameter");
|
||||
// duplicate definition so skip entire function
|
||||
|
@ -8052,6 +8053,7 @@ void Tokenizer::simplifyEnum()
|
|||
int exitScope = 0;
|
||||
bool simplify = false;
|
||||
bool hasClass = false;
|
||||
const Token *endScope = 0;
|
||||
for (Token *tok2 = tok1->next(); tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str() == "}")
|
||||
|
@ -8088,6 +8090,7 @@ void Tokenizer::simplifyEnum()
|
|||
// Not a duplicate enum..
|
||||
++level;
|
||||
}
|
||||
endScope = tok2->link();
|
||||
}
|
||||
else if (!pattern.empty() && Token::Match(tok2, pattern.c_str()))
|
||||
{
|
||||
|
@ -8112,6 +8115,8 @@ void Tokenizer::simplifyEnum()
|
|||
{
|
||||
// something with the same name.
|
||||
exitScope = level;
|
||||
if (endScope)
|
||||
tok2 = endScope->previous();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -304,6 +304,7 @@ private:
|
|||
TEST_CASE(enum19); // ticket #2536
|
||||
TEST_CASE(enum20); // ticket #2600
|
||||
TEST_CASE(enum21); // ticket #2720
|
||||
TEST_CASE(enum22); // ticket #2745
|
||||
|
||||
// remove "std::" on some standard functions
|
||||
TEST_CASE(removestd);
|
||||
|
@ -6517,6 +6518,21 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum22() // ticket #2745
|
||||
{
|
||||
const char code[] = "enum en { x = 0 };\n"
|
||||
"void f() {\n"
|
||||
" int x = 0;\n"
|
||||
" g(x);\n"
|
||||
"}\n"
|
||||
"void f2(int &x) {\n"
|
||||
" x+=1;\n"
|
||||
"}\n";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (style) Variable 'x' hides enumerator with same name\n"
|
||||
"[test.cpp:6] -> [test.cpp:1]: (style) Function parameter 'x' hides enumerator with same name\n", errout.str());
|
||||
}
|
||||
|
||||
void removestd()
|
||||
{
|
||||
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
||||
|
|
Loading…
Reference in New Issue