Issue 149479
Summary Clang 13-15 segfault during template instantiation with ill-formed nested type and RTTI operation
Labels clang
Assignees
Reporter Dong-hui-li
    ### Description
Clang versions 13-15 crash with segmentation fault when compiling C++20 code that:
1. Declares a local class with the same name as an outer scoped enum
2. Attempts to initialize that class with an enum value
3. Uses `typeid` operator on the invalid object

### Steps to Reproduce
1. Save the following code as `crash.cpp`:
```cpp
#include <typeinfo>

struct scoped {
    enum class scoped2 { RED };
};

template<auto>
struct S {
    void f() {
        class scoped2 e = scoped::scoped2::RED;
        typeid(e);
    }
};

int main() {
 S<scoped::scoped2::RED>{}.f();
}
```

2. Compile with affected Clang versions:
```bash
clang++-13 -std=c++20 crash.cpp
clang++-14 -std=c++20 crash.cpp
clang++-15 -std=c++20 crash.cpp
```

### Expected Behavior
Compiler should report type errors without crashing.

### Actual Behavior
Compiler crashes with segmentation fault during template instantiation.

### Affected Versions
- Clang 13.0.1
- Clang 14.0.0
- Clang 15.0.7

### Environment
- OS: Ubuntu 22.04 LTS
- Architecture: x86_64

### Notes
Clang 11 behaves correctly (reports errors without crashing).

### Expected Behavior
Compiler should report type errors without crashing

### Actual Behavior
Compiler crashes with segmentation fault during template instantiation

### Affected Versions
- Clang 13.0.1
- Clang 14.0.0
- Clang 15.0.7

### Additional Info
- Clang 11 behaves correctly (reports errors without crashing)
- Crash occurs in `Sema::SubstStmt` and `Sema::InstantiateFunctionDefinition`
- Stack trace and preprocessed files generated automatically by compiler
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to