Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13088 debug: Scope::checkVariable found variable 'impl' with varid 0. [varid0] #6810

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading