diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ea911b1acbe..e73fb34673c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9108,7 +9108,7 @@ static bool isAnonymousEnum(const Token* tok) while (Token::Match(end, "%name%|::")) end = end->next(); } - return end && Token::Match(end->link(), "} (| %type%| )| [,;[({=]"); + return end && Token::Match(end->link(), "} (| %type%| )| [*,;[({=]"); } void Tokenizer::simplifyStructDecl() @@ -9209,7 +9209,8 @@ void Tokenizer::simplifyStructDecl() } // check for initialization - if (Token::Match(after, "%any% (|{")) { + bool isFuncDecl = Token::Match(after, "%name% (") && Token::simpleMatch(after->linkAt(1), ") {"); + if (Token::Match(after, "%any% (|{") && !isFuncDecl) { after->insertToken("="); after = after->next(); const bool isEnum = start->str() == "enum"; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index af34625ca18..97073f0cee8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -218,6 +218,9 @@ class TestTokenizer : public TestFixture { TEST_CASE(vardecl29); // #9282 TEST_CASE(vardecl30); TEST_CASE(vardecl31); // function pointer init + TEST_CASE(vardecl32); + TEST_CASE(vardecl33); + TEST_CASE(vardecl34); TEST_CASE(vardecl_stl_1); TEST_CASE(vardecl_stl_2); TEST_CASE(vardecl_stl_3); @@ -2766,6 +2769,27 @@ class TestTokenizer : public TestFixture { } } + void vardecl32() { + { + const char code[] = "static enum { E } f() { return E; }"; + ASSERT_EQUALS("enum Anonymous0 { E } ; static enum Anonymous0 f ( ) { return E ; }", tokenizeAndStringify(code, true, Platform::Type::Native, false)); + } + } + + void vardecl33() { + { + const char code[] = "static enum { E } *f() { return NULL; }"; + ASSERT_EQUALS("enum Anonymous0 { E } ; static enum Anonymous0 * f ( ) { return NULL ; }", tokenizeAndStringify(code, true, Platform::Type::Native, false)); + } + } + + void vardecl34() { + { + const char code[] = "static enum { E } const *f() { return NULL; }"; + ASSERT_EQUALS("enum Anonymous0 { E } ; static enum Anonymous0 const * f ( ) { return NULL ; }", tokenizeAndStringify(code, true, Platform::Type::Native, false)); + } + } + void volatile_variables() { { const char code[] = "volatile int a=0;\n"