Skip to content

Commit

Permalink
Fix #12588 FP unusedFunction with forward-declared enum (#6232)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 4, 2024
1 parent 228f9cd commit 4503fbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8873,9 +8873,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

0 comments on commit 4503fbf

Please sign in to comment.