Skip to content

Commit 6527912

Browse files
Fix #12765 Assert failure in ExpressionAnalyzer() (#6520)
1 parent 77e4529 commit 6527912

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,9 +1677,9 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
16771677
}
16781678
}
16791679

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

16851685
for (const Scope * scope : exprScopes) {

test/testvarid.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ class TestVarID : public TestFixture {
250250
TEST_CASE(exprid9);
251251
TEST_CASE(exprid10);
252252
TEST_CASE(exprid11);
253+
TEST_CASE(exprid12);
253254

254255
TEST_CASE(structuredBindings);
255256
}
@@ -4216,6 +4217,25 @@ class TestVarID : public TestFixture {
42164217
ASSERT_EQUALS(exp, tokenizeExpr(code));
42174218
}
42184219

4220+
void exprid12()
4221+
{
4222+
const char code[] = "struct S { std::unique_ptr<int> p; };\n" // #12765
4223+
"namespace N {\n"
4224+
" struct T { void (*f)(S*); };\n"
4225+
" const T t = {\n"
4226+
" [](S* s) { s->p.release(); }\n"
4227+
" };\n"
4228+
"}\n";
4229+
const char* exp = "1: struct S { std :: unique_ptr < int > p ; } ;\n"
4230+
"2: namespace N {\n"
4231+
"3: struct T { void ( * f@2 ) ( S * ) ; } ;\n"
4232+
"4: const T t@3 = {\n"
4233+
"5: [ ] ( S * s@4 ) { s@4 .@UNIQUE p@5 .@UNIQUE release (@UNIQUE ) ; }\n"
4234+
"6: } ;\n"
4235+
"7: }\n";
4236+
ASSERT_EQUALS(exp, tokenizeExpr(code));
4237+
}
4238+
42194239
void structuredBindings() {
42204240
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
42214241
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",

0 commit comments

Comments
 (0)