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

    <tr>
        <th>Summary</th>
        <td>
            [libc++] Initialization of std::array of size 0 in constexpr contexts
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

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

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

<pre>
    ```c++
constexpr std::array<int, 0> a;
```
This fails to compile with libc++ (https://godbolt.org/z/drcGsW84x), since its zero-length `std::array` specialization has some dummy data (see #34839) that is left uninitialized.

This is quite unfortunate for a case like
```c++
template <int N>
constexpr auto getOnes() {
 std::array<int, N> a;
    a.fill(1);
    return a;
}
```
which will fail to compile only when used in a `constexpr` context with `N = 0` (https://godbolt.org/z/jxMGx1941). Using `std::array<int, N> a{};` fixes that, but it may also hide programming errors (i.e. missed elements) in the following actually intended initialization code for `N > 0` that would otherwise be diagnosed.

Microsoft's STL was in a very similar situation and fixed this just recently (see https://github.com/microsoft/STL/pull/3863), so I was hoping that maybe libc++ might want to follow. Seems like for libstdc++ this was never a problem since their `std::array<T, 0>` is actually empty.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE1v4kgT_jXNpRRk2oDhwCGZhNFIM3kPyas9t91lXNn-8HaVA-TXr9qQIUHZ1UqWEOD6eD7qMcy0C4gbtbhTi_uJGaSLaeNfTBNrxkkd7XGjlsXpaZS-y09xr4rbJgYWPPQJWKwqb1V5a1IyR1V-oyBKf4NClQ9gVHku-N3m9PW5I4bWkGOQCE30PTmEPUkHjurzKFB61Yn0nAfordLbXbR1dDKNaaf09k3prU3Nd_5jNT8ovc5jmUKDQMLwhineOAw76UAti6s9lwVwjw0ZR29GKAboDANHj2AH749gjZi8ACOC0mU5X5VrpdcgnREgBoetwBAokIxN0E7PSC8AieGvgQRhCG1M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