From 9949ae1b4f94d7262cff636cd40b454903ee7ad8 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 21 May 2019 03:40:36 -0500 Subject: [PATCH] Fix issue 8995: False Positive: Redundant code with initializer-list created object (#1844) --- lib/tokenize.cpp | 4 ++++ test/testincompletestatement.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1b402c8f8..58784adf5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 0608d8d65..ffaace99b 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -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 struct A { void operator()(int); };\n" + "void f() {\n" + "A{}(0);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void block() { check("void f() {\n" " ({ do_something(); 0; });\n"