From b8cda19ca65b3fbfe72beaa5d984e950745184d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 30 Mar 2011 21:57:01 +0200 Subject: [PATCH] Fixed #2655 (false positive: (warning) Redundant code: Found a statement that begins with numeric constant) --- lib/checkother.cpp | 4 ++++ test/testincompletestatement.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 56a807a0e..01ea707cc 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2767,7 +2767,11 @@ void CheckOther::checkIncompleteStatement() for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (tok->str() == "(") + { tok = tok->link(); + if (Token::simpleMatch(tok, ") {") && Token::simpleMatch(tok->next()->link(), "} ;")) + tok = tok->next()->link(); + } else if (Token::simpleMatch(tok, "= {")) tok = tok->next()->link(); diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index cc098d962..19e2bd7f9 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -68,6 +68,7 @@ private: TEST_CASE(structarray); TEST_CASE(conditionalcall); // ; 0==x ? X() : Y(); TEST_CASE(structinit); // #2462 : ABC abc{1,2,3}; + TEST_CASE(returnstruct); } void test1() @@ -192,6 +193,14 @@ private: check("struct A {};"); ASSERT_EQUALS("", errout.str()); } + + void returnstruct() + { + check("struct s foo() {\n" + " return (struct s){0,0};\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestIncompleteStatement)