From af26697ceb8157eaac3ea7193498436d22b30115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 28 Nov 2020 06:53:46 +0100 Subject: [PATCH] AST: Generate proper AST for 'f = []() -> foo&& {}' --- lib/tokenlist.cpp | 5 ++--- test/testtokenize.cpp | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index df754288c..dee16d2bc 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 36943ddc9..f0b24aaba 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 {};"));