diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2820da623..14e457025 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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))) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b3b3b8195..ee9f57d07 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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);"));