Skip to content

Commit

Permalink
Fix #12765 Assert failure in ExpressionAnalyzer() (#6520)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jun 14, 2024
1 parent 77e4529 commit 6527912
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit 6527912

Please sign in to comment.