llvm / llvm/llvm-project

[clang-repl][ASTMatcher] Failed template instantiation leaves orphan lambda closure declarations

Open
#214,968 2 comments 0 reactions 0 assignees View on GitHub
clang-query clang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:

```cpp
template struct O : A, B {};

template void f() {
auto a = [] {};
auto b = [] {};
O(a, b)();
}

template void f();
```

With an assertion-enabled build:

```console
./build/bin/clang-query -c='match classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType(recordType(hasDeclaration(cxxRecordDecl(hasAncestor(translationUnitDecl())))))))' repro.cpp -- -std=c++20
```

Crashes with:

```
Parent map should be complete!
UNREACHABLE executed at /llvm-project/clang/lib/ASTMatchers/ASTMatchFinder.cpp:1221!
```

Contributor guide

Open the contributing guide

Research direction

Start with the repro.cpp template-instantiation example and run the provided clang-query command against an assertion-enabled build. Read clang/lib/ASTMatchers/ASTMatchFinder.cpp around line 1221 to trace why the parent map is incomplete after the failed instantiation. Done means the reproducer no longer triggers the assertion and regression coverage protects the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.