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 #12765 Assert failure in ExpressionAnalyzer() #6520

Merged
merged 2 commits into from
Jun 14, 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/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,9 +1677,9 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
}
}

auto exprScopes = functionScopes; // functions + global lambdas
auto exprScopes = functionScopes; // functions + global lambdas + namespaces
std::copy_if(scopeList.front().nestedList.begin(), scopeList.front().nestedList.end(), std::back_inserter(exprScopes), [](const Scope* scope) {
return scope && scope->type == Scope::eLambda;
return scope && (scope->type == Scope::eLambda || scope->type == Scope::eNamespace);
});

for (const Scope * scope : exprScopes) {
Expand Down
20 changes: 20 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class TestVarID : public TestFixture {
TEST_CASE(exprid9);
TEST_CASE(exprid10);
TEST_CASE(exprid11);
TEST_CASE(exprid12);

TEST_CASE(structuredBindings);
}
Expand Down Expand Up @@ -4216,6 +4217,25 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(exp, tokenizeExpr(code));
}

void exprid12()
{
const char code[] = "struct S { std::unique_ptr<int> p; };\n" // #12765
"namespace N {\n"
" struct T { void (*f)(S*); };\n"
" const T t = {\n"
" [](S* s) { s->p.release(); }\n"
" };\n"
"}\n";
const char* exp = "1: struct S { std :: unique_ptr < int > p ; } ;\n"
"2: namespace N {\n"
"3: struct T { void ( * f@2 ) ( S * ) ; } ;\n"
"4: const T t@3 = {\n"
"5: [ ] ( S * s@4 ) { s@4 .@UNIQUE p@5 .@UNIQUE release (@UNIQUE ) ; }\n"
"6: } ;\n"
"7: }\n";
ASSERT_EQUALS(exp, tokenizeExpr(code));
}

void structuredBindings() {
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",
Expand Down
Loading