From 401f0de18bd1082bead45b60d2854c68b20c13a3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 27 Mar 2022 07:59:19 +0200 Subject: [PATCH] Fix #10929 FP constStatement with new (#3947) --- lib/tokenlist.cpp | 4 ++-- test/testtokenize.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 02f4cd95c..d2bd9d83e 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1540,7 +1540,7 @@ static Token * createAstAtToken(Token *tok, bool cpp) if (Token::Match(tok, "%type% <") && tok->linkAt(1) && !Token::Match(tok->linkAt(1), "> [({]")) return tok->linkAt(1); - if (cpp && Token::Match(tok, "%type% ::|<|%name%")) { + if (cpp && !tok->isKeyword() && Token::Match(tok, "%type% ::|<|%name%")) { Token *tok2 = tok; while (true) { if (Token::Match(tok2, "%name%|> :: %name%")) @@ -1559,7 +1559,7 @@ static Token * createAstAtToken(Token *tok, bool cpp) } } - if (Token::Match(tok, "%type% %name%|*|&|::") && tok->str() != "return") { + if (Token::Match(tok, "%type% %name%|*|&|::") && !Token::Match(tok, "return|new")) { int typecount = 0; Token *typetok = tok; while (Token::Match(typetok, "%type%|::|*|&")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 3e531ab55..1d9651cc3 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6032,6 +6032,7 @@ private: ASSERT_EQUALS("adelete", testAst("void f() { delete a; }")); ASSERT_EQUALS("Aa*A{new=", testAst("A* a = new A{};")); ASSERT_EQUALS("Aa*A12,{new=", testAst("A* a = new A{ 1, 2 };")); + ASSERT_EQUALS("Sv0[(new", testAst("new S(v[0]);")); // #10929 // placement new ASSERT_EQUALS("X12,3,(new ab,c,", testAst("new (a,b,c) X(1,2,3);"));