Fixed #3123 ([False Positive] Shadowed enum)

This commit is contained in:
Johan Samuelson 2011-10-22 13:43:53 +02:00 committed by Daniel Marjamäki
parent 84cd0bd585
commit 3d8fa2f76e
2 changed files with 19 additions and 8 deletions

View File

@ -7912,14 +7912,16 @@ void Tokenizer::simplifyEnum()
simplify = true; simplify = true;
hasClass = true; hasClass = true;
} else if (inScope && !exitThisScope && tok2->str() == enumName->str()) { } else if (inScope && !exitThisScope && tok2->str() == enumName->str()) {
if (Token::simpleMatch(tok2->previous(), "::") || if (!duplicateDefinition(&tok2, enumName)) {
Token::Match(tok2->next(), "::|[")) { if (Token::simpleMatch(tok2->previous(), "::") ||
// Don't replace this enum if: Token::Match(tok2->next(), "::|[")) {
// * it's preceded or followed by "::" // Don't replace this enum if:
// * it's followed by "[" // * it's preceded or followed by "::"
} else if (!duplicateDefinition(&tok2, enumName)) { // * it's followed by "["
simplify = true; } else {
hasClass = false; simplify = true;
hasClass = false;
}
} else { } else {
// something with the same name. // something with the same name.
exitScope = level; exitScope = level;

View File

@ -339,6 +339,7 @@ private:
TEST_CASE(enum25); // ticket #2966 TEST_CASE(enum25); // ticket #2966
TEST_CASE(enum26); // ticket #2975 (segmentation fault) TEST_CASE(enum26); // ticket #2975 (segmentation fault)
TEST_CASE(enum27); // ticket #3005 (segmentation fault) TEST_CASE(enum27); // ticket #3005 (segmentation fault)
TEST_CASE(enum28);
// remove "std::" on some standard functions // remove "std::" on some standard functions
TEST_CASE(removestd); TEST_CASE(removestd);
@ -6863,6 +6864,14 @@ private:
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
} }
void enum28() {
const char code[] = "enum { x=0 };\n"
"void f() { char x[4]; memset(x, 0, 4); \n"
"{ x } };\n"
"void g() { x; }";
ASSERT_EQUALS("; void f ( ) { char x [ 4 ] ; memset ( x , 0 , 4 ) ; { x } } ; void g ( ) { 0 ; }", tok(code, true));
}
void removestd() { void removestd() {
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);")); ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);")); ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));