From c49b94ff1c2614fdb6bcbf7370fe2e96dc590fc4 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 18 Sep 2024 01:13:47 +0200 Subject: [PATCH] Fix #13088 debug: Scope::checkVariable found variable 'impl' with varid 0. [varid0] --- lib/tokenize.cpp | 4 ++-- test/testvarid.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b36c079b8fd..e8d28b0bdf2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4638,7 +4638,7 @@ void Tokenizer::setVarIdPass1() // parse anonymous namespaces as part of the current scope if (!Token::Match(startToken->previous(), "union|struct|enum|namespace {") && - !(initlist && Token::Match(startToken->previous(), "%name%|>|>>|(|...") && Token::Match(startToken->link(), "} ,|{|}|)|..."))) { + !(initlist && Token::Match(startToken->previous(), "%name%|>|>>|(") && Token::Match(startToken->link(), "} ,|{|)|..."))) { if (tok->str() == "{") { bool isExecutable; @@ -4655,7 +4655,7 @@ void Tokenizer::setVarIdPass1() if (!(scopeStack.top().isStructInit || tok->strAt(-1) == "=")) variableMap.enterScope(); } - const bool isStructInit = scopeStack.top().isStructInit || tok->strAt(-1) == "=" || (initlist && !Token::Match(tok->tokAt(-1), "[)}]")); + const bool isStructInit = scopeStack.top().isStructInit || tok->strAt(-1) == "=" || (initlist && !Token::Match(tok->tokAt(-1), ")|}|...")); scopeStack.emplace(isExecutable, isStructInit, isEnumStart(tok), variableMap.getVarId()); initlist = false; } else { /* if (tok->str() == "}") */ diff --git a/test/testvarid.cpp b/test/testvarid.cpp index fff92515855..7cac5ae862a 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -2552,6 +2552,30 @@ class TestVarID : public TestFixture { "8: bool f ( p :: S2 & c@2 ) ;\n" "9: } ;\n", tokenize(code12)); + + const char code13[] = "template \n" // #13088 + "struct B {};\n" + "template \n" + "struct D : B... {\n" + " template \n" + " D(P&&... p) : B(std::forward

(p))... {}\n" + "};\n" + "template \n" + "struct S {\n" + " D d;\n" + "};\n"; + ASSERT_EQUALS("1: template < typename ... T >\n" + "2: struct B { } ;\n" + "3: template < typename ... T >\n" + "4: struct D : B < T > ... {\n" + "5: template < typename ... P >\n" + "6: D ( P && ... p@1 ) : B < T > ( std :: forward < P > ( p@1 ) ) ... { }\n" + "7: } ;\n" + "8: template < typename ... T >\n" + "9: struct S {\n" + "10: D < T ... > d@2 ;\n" + "11: } ;\n", + tokenize(code13)); } void varid_initListWithBaseTemplate() {