Fixed #1457 (PATCH: Variable hides enumerator with same name false negative)
This commit is contained in:
parent
d064d38d35
commit
f4d600e93b
|
@ -5293,6 +5293,10 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name)
|
||||||
}
|
}
|
||||||
else if (end->str() == ",")
|
else if (end->str() == ",")
|
||||||
{
|
{
|
||||||
|
// check for function argument
|
||||||
|
if (Token::Match(tok->previous(), "(|,"))
|
||||||
|
return false;
|
||||||
|
|
||||||
// find end of definition
|
// find end of definition
|
||||||
int level = 0;
|
int level = 0;
|
||||||
while (end && end->next() && (!Token::Match(end->next(), ";|)|>") ||
|
while (end && end->next() && (!Token::Match(end->next(), ";|)|>") ||
|
||||||
|
@ -5306,6 +5310,12 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name)
|
||||||
end = end->next();
|
end = end->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (end->str() == ")")
|
||||||
|
{
|
||||||
|
// check of function argument
|
||||||
|
if (tok->previous()->str() == ",")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (end)
|
if (end)
|
||||||
{
|
{
|
||||||
|
@ -5343,7 +5353,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// look backwards
|
// look backwards
|
||||||
if (tok->previous()->str() == "enum" ||
|
if (Token::Match(tok->previous(), "enum|,") ||
|
||||||
(Token::Match(tok->previous(), "%type%") &&
|
(Token::Match(tok->previous(), "%type%") &&
|
||||||
tok->previous()->str() != "return"))
|
tok->previous()->str() != "return"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -197,6 +197,7 @@ private:
|
||||||
TEST_CASE(enum8);
|
TEST_CASE(enum8);
|
||||||
TEST_CASE(enum9); // ticket 1404
|
TEST_CASE(enum9); // ticket 1404
|
||||||
TEST_CASE(enum10); // ticket 1445
|
TEST_CASE(enum10); // ticket 1445
|
||||||
|
TEST_CASE(enum11);
|
||||||
|
|
||||||
// remove "std::" on some standard functions
|
// remove "std::" on some standard functions
|
||||||
TEST_CASE(removestd);
|
TEST_CASE(removestd);
|
||||||
|
@ -3853,6 +3854,25 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enum11()
|
||||||
|
{
|
||||||
|
const char code[] = "int main()\n"
|
||||||
|
"{\n"
|
||||||
|
" enum { u, v };\n"
|
||||||
|
" A u = 1, v = 2;\n"
|
||||||
|
"}";
|
||||||
|
const char expected[] = "int main ( ) "
|
||||||
|
"{ "
|
||||||
|
"; "
|
||||||
|
"A u ; u = 1 ; A v ; v = 2 ; "
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(expected, tok(code, false));
|
||||||
|
|
||||||
|
checkSimplifyEnum(code);
|
||||||
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style) Variable 'u' hides enumerator with same name\n"
|
||||||
|
"[test.cpp:4] -> [test.cpp:3]: (style) Variable 'v' hides enumerator with same name\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void removestd()
|
void removestd()
|
||||||
{
|
{
|
||||||
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
||||||
|
|
Loading…
Reference in New Issue