Skip to content

Commit

Permalink
Handle delete
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 2, 2024
1 parent a4e34ba commit 90d62fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,10 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
tok = tok->link()->next();
compilePrecedence3(tok, state);
compileUnaryOp(tok2, state, nullptr);
if (Token::simpleMatch(tok2->previous(), ":: delete")) {
tok2->previous()->astOperand1(tok2);
state.op.pop();
}
}
// TODO: Handle sizeof
else break;
Expand Down
4 changes: 4 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6252,6 +6252,7 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("pint5[0{new=", testAst("p = new int* [5]{ 0 };"));
ASSERT_EQUALS("sSint(new::(new=", testAst("s = new S(::new int());")); // #12502
ASSERT_EQUALS("sS(new::=", testAst("s = ::new (ptr) S();")); // #12552
ASSERT_EQUALS("pdelete::return", testAst("return ::delete p;"));

// placement new
ASSERT_EQUALS("X12,3,(new ab,c,", testAst("new (a,b,c) X(1,2,3);"));
Expand Down Expand Up @@ -7084,6 +7085,9 @@ class TestTokenizer : public TestFixture {
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW(tokenizeAndStringify("{ for (()()) }"), InternalError); // #11643

ASSERT_NO_THROW(tokenizeAndStringify("S* g = ::new(ptr) S();")); // #12552
ASSERT_NO_THROW(tokenizeAndStringify("void f(int* p) { return ::delete p; }"));
}


Expand Down

0 comments on commit 90d62fe

Please sign in to comment.