Fix #10929 FP constStatement with new (#3947)

This commit is contained in:
chrchr-github 2022-03-27 07:59:19 +02:00 committed by GitHub
parent 1dd19dcaef
commit 401f0de18b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -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%|::|*|&")) {

View File

@ -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);"));