From d1f740a289a4ac0c3835cac3ecf02389a18fe5f6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 12 Mar 2022 06:17:37 +0100 Subject: [PATCH] Partial fix for #9384 varid 0 with lambda (II) (#3889) * Partial fix for #9384 varid 0 with lamba * Format * Undo * Undo * Partial fix for #9384 varid 0 with lambda (II) --- lib/tokenize.cpp | 10 +++++++++- test/testvarid.cpp | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c7843414f..3d4cc39a4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3512,7 +3512,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map %name% )")) { if (Token::Match(tok2->linkAt(2)->previous(), "if|for|while (")) return false; - if (!Token::Match(tok2->linkAt(2)->previous(), "%name% (")) + if (!Token::Match(tok2->linkAt(2)->previous(), "%name%|] (")) return false; } } else if (Token::Match(tok2, "&|&&")) { @@ -5232,6 +5232,14 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // Link < with > createLinks2(); + if (mTimerResults) { + Timer t("Tokenizer::tokenize::setVarId (2)", mSettings->showtime, mTimerResults); + setVarId(); + } + else { + setVarId(); + } + // Mark C++ casts for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, "const_cast|dynamic_cast|reinterpret_cast|static_cast <") && Token::simpleMatch(tok->linkAt(1), "> (")) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index e5751557a..fd18373ff 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -2636,7 +2636,7 @@ private: { const char code[] = "auto g = [](std::function p) {};\n"; const char exp[] = "1: auto g@1 ; g@1 = [ ] ( std :: function < void ( ) > p@2 ) { } ;\n"; - TODO_ASSERT_EQUALS(exp, "1: auto g@1 ; g@1 = [ ] ( std :: function < void ( ) > p ) { } ;\n", tokenize(code)); + ASSERT_EQUALS(exp, tokenize(code)); } }