Fix issue 8995: False Positive: Redundant code with initializer-list created object (#1844)

This commit is contained in:
Paul Fultz II 2019-05-21 03:40:36 -05:00 committed by Daniel Marjamäki
parent 9055682fdc
commit 9949ae1b4f
2 changed files with 19 additions and 0 deletions

View File

@ -7779,6 +7779,10 @@ bool Tokenizer::simplifyRedundantParentheses()
if (tok->str() != "(")
continue;
if (isCPP() && Token::simpleMatch(tok->previous(), "} (") &&
Token::Match(tok->previous()->link()->previous(), "%name%|> {"))
continue;
if (Token::simpleMatch(tok, "( {"))
continue;

View File

@ -80,6 +80,7 @@ private:
TEST_CASE(increment); // #3251 : FP for increment
TEST_CASE(cpp11init); // #5493 : int i{1};
TEST_CASE(cpp11init2); // #8449
TEST_CASE(cpp11init3); // #8995
TEST_CASE(block); // ({ do_something(); 0; })
TEST_CASE(mapindex);
TEST_CASE(commaoperator);
@ -285,6 +286,20 @@ private:
ASSERT_EQUALS("", errout.str());
}
void cpp11init3() {
check("struct A { void operator()(int); };\n"
"void f() {\n"
"A{}(0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("template<class> struct A { void operator()(int); };\n"
"void f() {\n"
"A<int>{}(0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void block() {
check("void f() {\n"
" ({ do_something(); 0; });\n"