From 455f8206534011d779ec3c338786fa5da0485cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 13 Feb 2025 14:26:05 +0100 Subject: [PATCH 1/5] add test --- test/testtokenize.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index fc67ea64b4f..af4811f942e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7027,6 +7027,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("Cc& MakeSpancdata.(csize.(,(", testAst("template constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {}")); ASSERT_EQUALS("Eqeq&key_typek&, eqkk,(", testAst("auto KeyTypeCanBeEq(const Eq& eq, const key_type& k) -> decltype(eq(k, k));")); + ASSERT_EQUALS("h{([= si. {return", testAst("auto h = []() -> decltype(s.i) { return {}; };")); } void astnoexcept() { ASSERT_EQUALS("noexceptaswap.b((", testAst("void f() noexcept(noexcept(a.swap(b))) {}")); From ffbf6fc9e5da00f3432ab10c01f9923e67700396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 13 Feb 2025 14:22:16 +0100 Subject: [PATCH 2/5] fix #11549 --- lib/tokenlist.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 42b54b0c042..f27ee57ed0b 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1025,8 +1025,14 @@ static void compilePrecedence2(Token *&tok, AST_state& state) else curlyBracket = curlyBracket->next(); } - if (curlyBracket && curlyBracket->originalName() == "->") + if (curlyBracket && curlyBracket->originalName() == "->") { + if (Token::simpleMatch(curlyBracket->next(), "decltype")) { + AST_state state2(state.cpp); + Token *tok2 = curlyBracket->tokAt(3); + compileExpression(tok2, state2); + } curlyBracket = findTypeEnd(curlyBracket->next()); + } if (curlyBracket && curlyBracket->str() == "{") { squareBracket->astOperand1(roundBracket); roundBracket->astOperand1(curlyBracket); From 0398658406c5d5295cb99c1cb1fba38e7c260d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 13 Feb 2025 17:17:43 +0100 Subject: [PATCH 3/5] more explicit matching --- lib/tokenlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index f27ee57ed0b..f9124dc43d6 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1026,7 +1026,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state) curlyBracket = curlyBracket->next(); } if (curlyBracket && curlyBracket->originalName() == "->") { - if (Token::simpleMatch(curlyBracket->next(), "decltype")) { + if (Token::simpleMatch(curlyBracket->next(), "decltype (")) { AST_state state2(state.cpp); Token *tok2 = curlyBracket->tokAt(3); compileExpression(tok2, state2); From bede3ce6e72580ad81497aa59fd13dd3a621ecbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 16 Feb 2025 13:11:16 +0100 Subject: [PATCH 4/5] add test for noexcept operator --- test/testtokenize.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index af4811f942e..617ae51f446 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7031,6 +7031,7 @@ class TestTokenizer : public TestFixture { } void astnoexcept() { ASSERT_EQUALS("noexceptaswap.b((", testAst("void f() noexcept(noexcept(a.swap(b))) {}")); + ASSERT_EQUALS("{([ noexceptaswap.b((", testAst("[]() noexcept(noexcept(a.swap(b))) {}")); } //Verify that returning a newly constructed object generates the correct AST even when the class name is scoped From 3b48c0e89577ea8d597f05687b3f5f810c1a89aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 13 Feb 2025 21:19:08 +0100 Subject: [PATCH 5/5] parse expressions in noexcept operator --- lib/tokenlist.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index f9124dc43d6..82e72df26dc 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1020,9 +1020,12 @@ static void compilePrecedence2(Token *&tok, AST_state& state) while (Token::Match(curlyBracket, "mutable|const|constexpr|consteval")) curlyBracket = curlyBracket->next(); if (Token::simpleMatch(curlyBracket, "noexcept")) { - if (Token::simpleMatch(curlyBracket->next(), "(")) + if (Token::simpleMatch(curlyBracket->next(), "(")) { + AST_state state2(state.cpp); + Token *tok2 = curlyBracket->tokAt(2); + compileExpression(tok2, state2); curlyBracket = curlyBracket->linkAt(1)->next(); - else + } else curlyBracket = curlyBracket->next(); } if (curlyBracket && curlyBracket->originalName() == "->") {