Skip to content

Commit

Permalink
Fix #13088 debug: Scope::checkVariable found variable 'impl' with var…
Browse files Browse the repository at this point in the history
…id 0. [varid0]
  • Loading branch information
chrchr-github committed Sep 17, 2024
1 parent d8debc2 commit c49b94f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() == "}") */
Expand Down
24 changes: 24 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,30 @@ class TestVarID : public TestFixture {
"8: bool f ( p :: S2 & c@2 ) ;\n"
"9: } ;\n",
tokenize(code12));

const char code13[] = "template <typename... T>\n" // #13088
"struct B {};\n"
"template <typename... T>\n"
"struct D : B<T>... {\n"
" template <typename... P>\n"
" D(P&&... p) : B<T>(std::forward<P>(p))... {}\n"
"};\n"
"template <typename... T>\n"
"struct S {\n"
" D<T...> 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() {
Expand Down

0 comments on commit c49b94f

Please sign in to comment.