Fixed #2466 (Tokenizer: simplification of enum)

This commit is contained in:
Daniel Marjamäki 2011-01-15 08:21:06 +01:00
parent 8ecba0af90
commit 5920dbb7e7
2 changed files with 15 additions and 3 deletions

View File

@ -7613,7 +7613,9 @@ void Tokenizer::simplifyEnum()
// find all uses of this enumerator and substitute it's value for it's name
if (enumName && (enumValue || (enumValueStart && enumValueEnd)))
{
const std::string pattern(className.empty() ? "" : (className + " :: " + enumName->str()).c_str());
const std::string pattern(className.empty() ?
std::string("") :
(className + " :: " + enumName->str()));
int level = 1;
bool inScope = true;
@ -7666,9 +7668,11 @@ void Tokenizer::simplifyEnum()
else if (inScope && !exitThisScope && tok2->str() == enumName->str())
{
if (Token::simpleMatch(tok2->previous(), "::") ||
Token::simpleMatch(tok2->next(), "::"))
Token::Match(tok2->next(), "::|["))
{
// Don't replace this enum if it's preceded or followed by "::"
// Don't replace this enum if:
// * it's preceded or followed by "::"
// * it's followed by "["
}
else if (!duplicateDefinition(&tok2, enumName))
{

View File

@ -276,6 +276,7 @@ private:
TEST_CASE(enum15);
TEST_CASE(enum16); // ticket #1988
TEST_CASE(enum17); // ticket #2381 (duplicate enums)
TEST_CASE(enum18); // #2466 (array with same name as enum constant)
// remove "std::" on some standard functions
TEST_CASE(removestd);
@ -6050,6 +6051,13 @@ private:
ASSERT_EQUALS("", errout.str());
}
void enum18() // ticket #2466 - array with same name as enum constant
{
const char code[] = "enum ab { a=0, b };\n"
"void f() { a[0]; }\n";
ASSERT_EQUALS("; void f ( ) { a [ 0 ] ; }", tok(code, false));
}
void removestd()
{
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));