From e74e4c6934706afcdebcc19be058926a2551b5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 26 Aug 2017 11:59:09 +0200 Subject: [PATCH] Fixed #8030 (False positive 'constStatement' when indexing with {}) --- lib/checkother.cpp | 5 +---- test/testincompletestatement.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ac9b4dbba..f45d70f95 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1568,11 +1568,8 @@ void CheckOther::checkIncompleteStatement() return; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (tok->str() == "(") { + if (Token::Match(tok, "(|[")) 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 54d41486f..e82ea529e 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -81,6 +81,7 @@ private: TEST_CASE(increment); // #3251 : FP for increment TEST_CASE(cpp11init); // #5493 : int i{1}; TEST_CASE(block); // ({ do_something(); 0; }) + TEST_CASE(mapindex); } void test1() { @@ -279,6 +280,13 @@ private: "}"); ASSERT_EQUALS("", errout.str()); } + + void mapindex() { + check("void f() {\n" + " map[{\"1\",\"2\"}]=0;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestIncompleteStatement)