fix #2828 (false positive: Function parameter 'STYLE' hides enumerator with same name)
This commit is contained in:
parent
97d47fa20e
commit
6635ed4630
|
@ -7873,7 +7873,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name)
|
|||
}
|
||||
else if (end->str() == ")")
|
||||
{
|
||||
// check of function argument
|
||||
// check for function argument
|
||||
if (tok->previous()->str() == ",")
|
||||
return false;
|
||||
}
|
||||
|
@ -7882,6 +7882,10 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name)
|
|||
{
|
||||
if (Token::simpleMatch(end, ") {")) // function parameter ?
|
||||
{
|
||||
// make sure it's not a conditional
|
||||
if (Token::Match(end->link()->previous(), "if|for|while"))
|
||||
return false;
|
||||
|
||||
// look backwards
|
||||
if (tok->previous()->str() == "enum" ||
|
||||
(Token::Match(tok->previous(), "%type%") &&
|
||||
|
|
|
@ -308,6 +308,7 @@ private:
|
|||
TEST_CASE(enum21); // ticket #2720
|
||||
TEST_CASE(enum22); // ticket #2745
|
||||
TEST_CASE(enum23); // ticket #2804
|
||||
TEST_CASE(enum24); // ticket #2828
|
||||
|
||||
// remove "std::" on some standard functions
|
||||
TEST_CASE(removestd);
|
||||
|
@ -6619,6 +6620,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum24() // ticket #2828
|
||||
{
|
||||
const char code[] = "enum EnumName { STYLE = 0x0001 };\n"
|
||||
"void f(long style) {\n"
|
||||
" if (style & STYLE) { }\n"
|
||||
"}\n";
|
||||
const char expected[] = "; void f ( long style ) { if ( style & 1 ) { } }";
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void removestd()
|
||||
{
|
||||
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
||||
|
|
Loading…
Reference in New Issue