diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 03b73db94..7b62745e5 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -483,7 +483,7 @@ static bool iscpp11init(const Token * const tok) endtok = nameToken->linkAt(1)->linkAt(1); else return false; - if (Token::Match(nameToken, "else|try|do")) + if (Token::Match(nameToken, "else|try|do|const|override|volatile|&|&&")) return false; // There is no initialisation for example here: 'class Fred {};' if (!Token::simpleMatch(endtok, "} ;")) diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 66b7eee79..0608d8d65 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -86,6 +86,7 @@ private: TEST_CASE(redundantstmts); TEST_CASE(vardecl); TEST_CASE(archive); // ar & x + TEST_CASE(ast); } void test1() { @@ -379,6 +380,11 @@ private: "}", true); ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '&'\n", errout.str()); } + + void ast() { + check("struct c { void a() const { for (int x=0; x;); } };", true); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestIncompleteStatement) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 3b93fcdda..29ebb75a4 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7091,6 +7091,12 @@ private: // C++17: if (expr1; expr2) ASSERT_EQUALS("ifx3=y;(", testAst("if (int x=3; y)")); + + ASSERT_EQUALS("a( forx0=x;;(", testAst("struct c { void a() const { for (int x=0; x;); } };")); + // TODO: We dont correctly parse ref qualifiers + TODO_ASSERT_EQUALS("a( forx0=x;;(", "a({&", testAst("struct c { void a() & { for (int x=0; x;); } };")); + TODO_ASSERT_EQUALS("a( forx0=x;;(", "a({&&", testAst("struct c { void a() && { for (int x=0; x;); } };")); + } void astexpr2() { // limit for large expressions