diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 42b54b0c042..82e72df26dc 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1020,13 +1020,22 @@ 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() == "->") + 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); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index fc67ea64b4f..617ae51f446 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7027,9 +7027,11 @@ 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))) {}")); + 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