Fixed #1355 (Fixed enum bug when expression contain comma)

This commit is contained in:
Robert Reif 2010-02-06 09:49:56 +01:00 committed by Daniel Marjamäki
parent cbc853fdba
commit b78845174d
2 changed files with 19 additions and 1 deletions

View File

@ -5110,10 +5110,20 @@ void Tokenizer::simplifyEnum()
tok1 = tok1->tokAt(2);
enumValueStart = tok1;
enumValueEnd = tok1;
while (!Token::Match(enumValueEnd->next(), ",|}"))
int level = 0;
while (enumValueEnd->next() && (enumValueEnd->next()->str() != "}") &&
((enumValueEnd->next()->str() != ",") || level))
{
if (enumValueEnd->next()->str() == "(" || enumValueEnd->next()->str() == "[")
level++;
else if (enumValueEnd->next()->str() == ")" || enumValueEnd->next()->str() == "]")
level--;
enumValueEnd = enumValueEnd->next();
}
lastEnumValueStart = enumValueStart;
lastEnumValueEnd = enumValueEnd;
tok1 = enumValueEnd;
}
if (enumName && (enumValue || (enumValueStart && enumValueEnd)))

View File

@ -187,6 +187,7 @@ private:
TEST_CASE(enum3);
TEST_CASE(enum4);
TEST_CASE(enum5);
TEST_CASE(enum6);
// remove "std::" on some standard functions
TEST_CASE(removestd);
@ -3478,6 +3479,13 @@ private:
ASSERT_EQUALS("; int sum ; sum = 508 ;", tok(code, true));
}
void enum6()
{
const char code[] = "enum { a = MAC(A, B, C) }; void f(a) { }";
const char expected[] = "; void f ( MAC ( A , B , C ) ) { }";
ASSERT_EQUALS(expected, tok(code, false));
}
void removestd()
{
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));