Skip to content

Commit b8cda19

Browse files
author
Daniel Marjamäki
committed
Fixed cppcheck-opensource#2655 (false positive: (warning) Redundant code: Found a statement that begins with numeric constant)
1 parent 97328f0 commit b8cda19

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/checkother.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,11 @@ void CheckOther::checkIncompleteStatement()
27672767
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
27682768
{
27692769
if (tok->str() == "(")
2770+
{
27702771
tok = tok->link();
2772+
if (Token::simpleMatch(tok, ") {") && Token::simpleMatch(tok->next()->link(), "} ;"))
2773+
tok = tok->next()->link();
2774+
}
27712775

27722776
else if (Token::simpleMatch(tok, "= {"))
27732777
tok = tok->next()->link();

test/testincompletestatement.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class TestIncompleteStatement : public TestFixture
6868
TEST_CASE(structarray);
6969
TEST_CASE(conditionalcall); // ; 0==x ? X() : Y();
7070
TEST_CASE(structinit); // #2462 : ABC abc{1,2,3};
71+
TEST_CASE(returnstruct);
7172
}
7273

7374
void test1()
@@ -192,6 +193,14 @@ class TestIncompleteStatement : public TestFixture
192193
check("struct A {};");
193194
ASSERT_EQUALS("", errout.str());
194195
}
196+
197+
void returnstruct()
198+
{
199+
check("struct s foo() {\n"
200+
" return (struct s){0,0};\n"
201+
"}");
202+
ASSERT_EQUALS("", errout.str());
203+
}
195204
};
196205

197206
REGISTER_TEST(TestIncompleteStatement)

0 commit comments

Comments
 (0)