From 343a23135d8403db755f4118ca33df060bf478e5 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 30 Mar 2022 19:22:01 +0200 Subject: [PATCH] Fix #10932 FP constStatement with reference and direct initialization (#3952) --- lib/tokenlist.cpp | 4 ++-- test/testincompletestatement.cpp | 10 ++++++++++ test/testtokenize.cpp | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 4b16cbb52..aa4e14772 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -643,7 +643,7 @@ static bool iscpp11init_impl(const Token * const tok) endtok = nameToken->linkAt(1); else if (Token::Match(nameToken,"%name% <") && Token::simpleMatch(nameToken->linkAt(1),"> {")) endtok = nameToken->linkAt(1)->linkAt(1); - else if (Token::Match(nameToken->previous(), "%name% ( {")) + else if (Token::Match(nameToken->previous(), "%name%|> ( {")) endtok = nameToken->linkAt(1); else return false; @@ -1574,7 +1574,7 @@ static Token * createAstAtToken(Token *tok, bool cpp) if (typetok && typecount >= 2 && !Token::Match(tok, "return|throw") && - Token::Match(typetok->previous(), "%name% (") && + Token::Match(typetok->previous(), "%name% ( !!*") && typetok->previous()->varId() == 0 && !typetok->previous()->isKeyword() && Token::Match(typetok->link(), ") const|;|{")) diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 2fb53cc1b..829d0368f 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -309,6 +309,11 @@ private: " int x{1};\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("std::vector f(int* p) {\n" + " return std::vector({ p[0] });\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void cpp11init2() { @@ -580,6 +585,11 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f(int* p) {\n" // #10932 + " int& r(*p[0]);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("struct S { int i; };\n" // #10917 "bool f(S s) {\n" " return [](int i) { return i > 0; }(s.i);\n" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5a7b0ec44..9ebe5325b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6185,6 +6185,7 @@ private: ASSERT_EQUALS("var1ab::23,{,4ab::56,{,{,{{", testAst("auto var{{1,a::b{2,3}}, {4,a::b{5,6}}};")); ASSERT_EQUALS("var{{,{,{{", testAst("auto var{ {{},{}}, {} };")); ASSERT_EQUALS("fXYabcfalse==CD:?,{,{(", testAst("f({X, {Y, abc == false ? C : D}});")); + ASSERT_EQUALS("stdvector::p0[{(return", testAst("return std::vector({ p[0] });")); // Initialization with decltype(expr) instead of a type ASSERT_EQUALS("decltypex((", testAst("decltype(x)();")); @@ -6214,6 +6215,7 @@ private: ASSERT_EQUALS("a1[\"\"=", testAst("char a[1]=\"\";")); ASSERT_EQUALS("charp*(3[char5[3[new=", testAst("char (*p)[3] = new char[5][3];")); ASSERT_EQUALS("varp=", testAst("const int *var = p;")); + ASSERT_EQUALS("intrp0[*(&", testAst("int& r(*p[0]);")); // #9127 const char code1[] = "using uno::Ref;\n"