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"