Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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";
Expand Down
24 changes: 24 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down