<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/123129>123129</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang Segmentation Fault When Instantiating a Template with Dynamic Array Initialization
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          SOHAIBALOUSSI
      </td>
    </tr>
</table>

<pre>
    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)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVNFuqzgQ_RrnZVRkhiTAAw8kbbSVrnR3lV7tY2XMELwLNmub9rZfv7IhbTcrrTZCQNB45sw5Z0Y4py6aqGK7A9vdb8Tse2Or8_df6sdD_e37j_P5cdOY9q3yvXLQzBcwUs7WwWtPGqQZJzUofYEjwwPDA0jTErwq38NxEPoCKSY8SYFh8aOZtZ_XD3dpOcf_GcOSZTXj4arB0aUT8-BBOfBWXS5kqYV2tqGGp3EahCdQ2nmhvRJeGb0gUVp5JQb1HgIFtG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