From 3cb46b047fa4a179513725c0dc7fe7cc572acb82 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 15 Mar 2024 12:38:52 +0100 Subject: [PATCH] Fix #12502 error: Cyclic reverse analysis with scoped new --- lib/tokenlist.cpp | 2 +- test/testtokenize.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index d8048af2ee3..3062451449a 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -746,7 +746,7 @@ static void compileTerm(Token *&tok, AST_state& state) tok = tok->next(); } while (Token::Match(tok, "%name%|%str%")); } else if (tok->isName()) { - if (Token::Match(tok, "return|case") || (state.cpp && tok->str() == "throw")) { + if (Token::Match(tok, "return|case") || (state.cpp && (tok->str() == "throw" || Token::simpleMatch(tok->tokAt(-1), ":: new")))) { if (tok->str() == "case") state.inCase = true; const bool tokIsReturn = tok->str() == "return"; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f6a0a67f4eb..2d4f514f99d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6220,6 +6220,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("pint0{new=", testAst("p = new int*{ 0 };")); ASSERT_EQUALS("pint5[{new=", testAst("p = new int* [5]{};")); ASSERT_EQUALS("pint5[0{new=", testAst("p = new int* [5]{ 0 };")); + ASSERT_EQUALS("sSint(new::(new=", testAst("s = new S(::new int());")); // #12502 // placement new ASSERT_EQUALS("X12,3,(new ab,c,", testAst("new (a,b,c) X(1,2,3);"));