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
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8870,9 +8870,9 @@ void Tokenizer::simplifyStructDecl()
const Token * const type = tok->next();
Token *next = tok->tokAt(2);

while (next && next->str() != "{")
while (next && !Token::Match(next, "[{;]"))
next = next->next();
if (!next)
if (!next || next->str() == ";")
continue;
Token* after = next->link();
if (!after)
Expand Down
23 changes: 23 additions & 0 deletions test/testsimplifytokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class TestSimplifyTokens : public TestFixture {
TEST_CASE(simplifyStructDecl6); // ticket #3732
TEST_CASE(simplifyStructDecl7); // ticket #476 (static anonymous struct array)
TEST_CASE(simplifyStructDecl8); // ticket #7698
TEST_CASE(simplifyStructDecl9);

// register int var; => int var;
// inline int foo() {} => int foo() {}
Expand Down Expand Up @@ -1249,6 +1250,28 @@ class TestSimplifyTokens : public TestFixture {
ASSERT_EQUALS("enum class J : short { x , y , z } ; enum J j ; j = x ;", tok("enum class J : short { x, y, z } j{x};"));
}

void simplifyStructDecl9() {
const char* code = "enum E : int;\n" // #12588
"void f() {}\n"
"namespace {\n"
" struct S {\n"
" explicit S(int i) : m(i) {}\n"
" int m;\n"
" };\n"
"}\n"
"void g() { S s(0); }\n";
const char* exp = "enum E : int ; "
"void f ( ) { } "
"namespace { "
"struct S { "
"explicit S ( int i ) : m ( i ) { } "
"int m ; "
"} ; "
"} "
"void g ( ) { S s ( 0 ) ; }";
ASSERT_EQUALS(exp, tok(code));
}

void removeUnwantedKeywords() {
ASSERT_EQUALS("int var ;", tok("register int var ;"));
ASSERT_EQUALS("short var ;", tok("register short int var ;"));
Expand Down