llvm / llvm/llvm-project

Clang++ crashes when instantiating a particular template class with a static constexpr data member.

Open
#165,988 3 comments 0 reactions 0 assignees View on GitHub
clang:codegen crash
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This code makes clang++ to crash:

```c++
template
struct S {
static constexpr char c{};
static constexpr decltype(&c) p = nullptr;
};

auto f() {
return S::p;
}
```

GCC and MSVC have no issue to compile the code.

https://godbolt.org/z/edr4h4v99

If instead of being deduced, the type of `S::p` or the return type of `f` is explicitly given (`const char*`), then compilation succeeds.

Contributor guide

Open the contributing guide

Research direction

Start by compiling the reduced C++ reproducer with clang++ from the linked Compiler Explorer example and compare it with the versions that explicitly specify the pointer or return type. Use the crash location and template-instantiation path to identify the affected compiler subsystem. Done means the reproducer no longer crashes and coverage prevents this regression.

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
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.