Issue 123129
Summary Clang Segmentation Fault When Instantiating a Template with Dynamic Array Initialization
Labels clang
Assignees
Reporter SOHAIBALOUSSI
    this bug occurs when compiling C++ code with Clang 12.0.1 (Ubuntu 12.0.1-19ubuntu3):

A segfault is triggered during template instantiation when initializing a dynamic array in the constructor of a class template
```SQL
./Array.hpp:19:19: error: cannot determine allocated array size from initializer
        arr = new T[]();
 ^
main.cpp:5:16: note: in instantiation of member function 'Array<int>::Array' requested here
    Array<int> arr(10);
 ^
```
the bug arises when attempting to allocate an array with the following constructor signature in Array.hpp:

```c++
template<typename T>
class Array {
public:
    Array(size_t size) {
        arr = new T[]();  // Error: Cannot determine array size
    }
};
```

the Clang compiler crashes with a segmentation fault, and the following stack dump is provided in the report

```
#0 0x00007fa27317e2a1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
...
#34 0x000000000040ea25 _start (/usr/lib/llvm-12/bin/clang+0x40ea25)
```

[main-7097c7.zip](https://github.com/user-attachments/files/18430962/main-7097c7.zip)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to