AST: Generate proper AST for 'f = []() -> foo&& {}'

This commit is contained in:
Daniel Marjamäki 2020-11-28 06:53:46 +01:00
parent 484b68c550
commit af26697ceb
2 changed files with 3 additions and 3 deletions

View File

@ -558,7 +558,7 @@ static bool iscast(const Token *tok, bool cpp)
static Token* findTypeEnd(Token* tok)
{
while (Token::Match(tok, "%name%|.|::|*|&|<|(|template|decltype|sizeof")) {
while (Token::Match(tok, "%name%|.|::|*|&|&&|<|(|template|decltype|sizeof")) {
if (Token::Match(tok, "(|<"))
tok = tok->link();
if (!tok)
@ -949,9 +949,8 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
Token* curlyBracket = roundBracket->link()->next();
if (Token::Match(curlyBracket, "mutable|const|noexcept"))
curlyBracket = curlyBracket->next();
if (curlyBracket && curlyBracket->originalName() == "->") {
if (curlyBracket && curlyBracket->originalName() == "->")
curlyBracket = findTypeEnd(curlyBracket->next());
}
if (curlyBracket && curlyBracket->str() == "{") {
squareBracket->astOperand1(roundBracket);
roundBracket->astOperand1(curlyBracket);

View File

@ -8023,6 +8023,7 @@ private:
ASSERT_EQUALS("{([return", testAst("return []() -> decltype(0) {};"));
ASSERT_EQUALS("x{(&[=", testAst("x = [&]()->std::string const & {};"));
ASSERT_EQUALS("f{([=", testAst("f = []() -> foo* {};"));
ASSERT_EQUALS("f{([=", testAst("f = []() -> foo&& {};"));
ASSERT_EQUALS("f{([=", testAst("f = [](void) mutable -> foo* {};"));
ASSERT_EQUALS("f{([=", testAst("f = []() mutable {};"));