From ae6455f3f4ecd9451906ef9b81d5b9ba1466969c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 11 May 2025 16:19:22 +0200 Subject: [PATCH 1/3] add test --- test/testtokenize.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c9909adb330..649b65d43e7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -456,6 +456,8 @@ class TestTokenizer : public TestFixture { TEST_CASE(simplifyIfSwitchForInit4); TEST_CASE(simplifyIfSwitchForInit5); + TEST_CASE(newPlacementArgsCppInit); // #13775 + TEST_CASE(cpp20_default_bitfield_initializer); TEST_CASE(cpp11init); @@ -8070,6 +8072,18 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("void f ( ) { if ( [ ] { ; } ) { } }", tokenizeAndStringify(code, settings)); } + void newPlacementArgsCppInit() { // #13775 + const char code[] = "::new(nullptr) int {};"; + SimpleTokenizer tokenizer(settings1, *this); + tokenizer.tokenize(code); + const Token *inttok = Token::findsimplematch(tokenizer.tokens(), "int"); + ASSERT(inttok); + const Token *brace = inttok->next(); + ASSERT(brace); + ASSERT_EQUALS(brace->astOperand1(), inttok); + ASSERT_EQUALS(brace->astOperand2(), (const Token*) nullptr); + } + void cpp20_default_bitfield_initializer() { const Settings s1 = settingsBuilder().cpp(Standards::CPP20).build(); const char code[] = "struct S { int a:2 = 0; };"; From ca80d8afc7245f0b5120214724854dbf7e71e5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 11 May 2025 16:00:20 +0200 Subject: [PATCH 2/3] fix #13775 --- lib/tokenlist.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index a180ed1c51e..6154ed77865 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -834,6 +834,10 @@ static void compileTerm(Token *&tok, AST_state& state) if (precedes(tok,end)) // typically for something like `MACRO(x, { if (c) { ... } })`, where end is the last curly, and tok is the open curly for the if tok = end; } + } else if (tok->next() == end) { + tok->astOperand1(state.op.top()); + state.op.pop(); + tok = tok->next(); } else compileBinOp(tok, state, compileExpression); if (tok != end) From ee46f4b2db092c53aa3b7372a8627ce417029679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 11 May 2025 16:51:50 +0200 Subject: [PATCH 3/3] ci fix --- test/testtokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 649b65d43e7..21302952660 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8081,7 +8081,7 @@ class TestTokenizer : public TestFixture { const Token *brace = inttok->next(); ASSERT(brace); ASSERT_EQUALS(brace->astOperand1(), inttok); - ASSERT_EQUALS(brace->astOperand2(), (const Token*) nullptr); + ASSERT_EQUALS(brace->astOperand2(), static_cast(nullptr)); } void cpp20_default_bitfield_initializer() {