From 3630e9c49d3beb34158bd18179c9536e7893a929 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 24 Mar 2022 22:07:21 +0100 Subject: [PATCH] Fix #10874 FP constStatement with extra parentheses in declaration (#3931) --- lib/tokenlist.cpp | 4 ++-- test/testincompletestatement.cpp | 8 ++++++++ test/testtokenize.cpp | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 933dd11d4..f5cb0281a 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -814,7 +814,7 @@ static void compileTerm(Token *&tok, AST_state& state) state.op.push(tok); if (Token::Match(tok, "%name% <") && tok->linkAt(1)) tok = tok->linkAt(1); - else if (Token::Match(tok, "%name% ...")) + else if (Token::Match(tok, "%name% ...") || (state.op.size() == 1 && Token::Match(tok->previous(), "( %name% ) ="))) tok = tok->next(); tok = tok->next(); if (Token::Match(tok, "%str%")) { @@ -1467,7 +1467,7 @@ static Token * createAstAtToken(Token *tok, bool cpp) while (tok2 && tok2 != endPar && tok2->str() != ";") { if (tok2->str() == "<" && tok2->link()) { tok2 = tok2->link(); - } else if (Token::Match(tok2, "%name% %op%|(|[|.|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) { + } else if (Token::Match(tok2, "%name% )| %op%|(|[|.|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) { init1 = tok2; AST_state state1(cpp); compileExpression(tok2, state1); diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 52b64053e..a0bf24ada 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -504,6 +504,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("struct T {\n" // #10874 + " T* p;\n" + "};\n" + "void f(T* t) {\n" + " for (decltype(t->p) (c) = t->p; ;) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void f(int i, std::vector v);\n" // #10880 "void g() {\n" " f(1, { static_cast(nullptr) });\n" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6bf4434ec..5bfdbaf56 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6213,6 +6213,12 @@ private: ASSERT_EQUALS("decltypex( var1=", testAst("decltype(x) var = 1;")); ASSERT_EQUALS("a1bdecltypet((>2,(", testAst("a(1 > b(decltype(t)), 2);")); // #10271 ASSERT_EQUALS("decltypex({01:?", testAst("decltype(x){} ? 0 : 1;")); + + ASSERT_EQUALS("Tp* Tt* forctp.=;;( tp.", testAst("struct T { T* p; };\n" // #10874 + "void f(T * t) {\n" + " for (decltype(t->p) (c) = t->p; ;) {}\n" + "}\n")); + ASSERT_EQUALS("x0=a, stdtie::a(x=", testAst("int x = 0, a; std::tie(a) = x;\n")); } void astunaryop() { // unary operators