From ecac93ebedf4e88be382424f8178a3abbb6e46e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 19 Jan 2011 18:37:33 +0100 Subject: [PATCH] Fixed #2462 (false positive: (warning) Redundant code: Found a statement that begins with numeric constant) --- lib/checkother.cpp | 3 +++ test/testincompletestatement.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 33465af8b..de54f9029 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2365,6 +2365,9 @@ void CheckOther::checkIncompleteStatement() else if (Token::simpleMatch(tok, "= {")) tok = tok->next()->link(); + else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), "%type% %var%")) + tok = tok->link(); + else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num%")) { // bailout if there is a "? :" in this statement diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 622a0cd9f..850cb41ee 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -67,6 +67,7 @@ private: TEST_CASE(structarraynull); TEST_CASE(structarray); TEST_CASE(conditionalcall); // ; 0==x ? X() : Y(); + TEST_CASE(structinit); // #2462 : ABC abc{1,2,3}; } void test1() @@ -178,6 +179,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); } + + void structinit() + { + check("void f() {\n" + " ABC abc{1,2,3};\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestIncompleteStatement)