Destructor lookup on an uninstantiated class template specialization crashes
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Minimal repro:
```c++
template struct Q {};
// The following line fixes it:
// Q force;
bool b = requires(void f(const Q (&)[])) { f({}); };
```
`clang++ -std=c++20 -fsyntax-only` crashes, gcc [accepts it](https://godbolt.org/z/bY41fPhvo). Here is the stacktrace for [clang-22](https://godbolt.org/z/d9K8769xo) and for [clang trunk](https://godbolt.org/z/3qxE3xWfb). It looks like this crash exists since [clang-10](https://godbolt.org/z/jdhrT9Wvn).
If I got this right: checking `f({})` initializes a temporary array of `const Q` and looks for the element type's destructor. At that point `const Q` was never instantiated so the lookup runs on a record with no definition. This generates the crash.
Adding an explicit instantiation `Q force` fixes this. Also using a sized array fixes this.
Contributor guide
Research direction
Start by reproducing the crash with the minimal C++20 example using clang++ -fsyntax-only and compare the linked Clang stack traces with GCC's accepted result. Trace destructor lookup for the uninstantiated Q specialization during f({}) array initialization. Done means the reproducer no longer crashes and a regression test covers the unsized-array case.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100