Fixed #8030 (False positive 'constStatement' when indexing with {})

This commit is contained in:
Daniel Marjamäki 2017-08-26 11:59:09 +02:00
parent cc97834e88
commit e74e4c6934
2 changed files with 9 additions and 4 deletions

View File

@ -1568,11 +1568,8 @@ void CheckOther::checkIncompleteStatement()
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (tok->str() == "(") { if (Token::Match(tok, "(|["))
tok = tok->link(); tok = tok->link();
if (Token::simpleMatch(tok, ") {") && Token::simpleMatch(tok->next()->link(), "} ;"))
tok = tok->next()->link();
}
else if (Token::simpleMatch(tok, "= {")) else if (Token::simpleMatch(tok, "= {"))
tok = tok->next()->link(); tok = tok->next()->link();

View File

@ -81,6 +81,7 @@ private:
TEST_CASE(increment); // #3251 : FP for increment TEST_CASE(increment); // #3251 : FP for increment
TEST_CASE(cpp11init); // #5493 : int i{1}; TEST_CASE(cpp11init); // #5493 : int i{1};
TEST_CASE(block); // ({ do_something(); 0; }) TEST_CASE(block); // ({ do_something(); 0; })
TEST_CASE(mapindex);
} }
void test1() { void test1() {
@ -279,6 +280,13 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void mapindex() {
check("void f() {\n"
" map[{\"1\",\"2\"}]=0;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestIncompleteStatement) REGISTER_TEST(TestIncompleteStatement)