<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57384>57384</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Array literals can't be passed to `constexpr` functions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
rejects-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tbaederr
</td>
</tr>
</table>
<pre>
```c++
constexpr int add(const int f[]) {
const int res = f[0] + f[1] + f[2];
return res;
}
static_assert(add((const int[]){1, 2, 3}) == 6);
```
this does not compile with clang:
```
<source>:7:17: error: static_assert expression is not an integral constant expression
static_assert(add((const int[]){1, 2, 3}) == 6);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:7:34: note: destroying object '{1, 2, 3}' whose lifetime has already ended
static_assert(add((const int[]){1, 2, 3}) == 6);
^
<source>:7:17: note: in call to 'add(&(const int[3]){1, 2, 3}[0])'
static_assert(add((const int[]){1, 2, 3}) == 6);
^
1 error generated.
Compiler returned: 1
```
[Godbolt](https://godbolt.org/z/jx6zKPrY7)
It compiles in G++ and certainly looks alright for my eyes.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VMty2yAU_Rq0YeIRoIe90CKJk0ynm2676iBxLZFi8ABK4nx9L1IUu2nSXaJBj8sFdM65j9apY0OqfB4d4Vdp5FuSX9LO2RDh6eCptpFKpQhfT3OTvSPlFSm3hG8oqZctlJ4WeAiUiO20MMeVFE-eDHZu8HSGOO33EEdv0-bTLKm3iz9EGXX3S4YAPiKeGdU5sFdYiIoRfk15eoh0RoIqtglTlfzL-a_0ZzMOOlDlEL11EfnsD9oAfdRxoJ2Rtifi8mXfe7uJuA5u9B0QcYMra7xZelDw3vn08RcFmvSFELSzVM9_lDbRgN5LM6sp7fmyz1SCvrlIeUPqzxwfSSaKpBSqAemtIETvjtr21LX30EXMnvodUjV9HFwAavQOot4DHWSg0niQ6kjBKlBfKd4_V1Lz_zmyENaWdtIYGl1iuoCr3uATHwGc6y25UKYvTpfJweZspz1Y8DKCWs3z13Mx-Zcqx3ggWfZ-HZVXd061zsQJ1HqI8RBS6fFbHP3sWjnfo_WM9_1T9fz9h_9ZJ4Bn5fnttYRDkvVu7nBYZIp2qITU1hypce73lCm6H7CzIfI9JswRwiqDhlUVK1lZsjxTjVAbsZFZ1NFAc-m9xM06IkkTMGQWBY-0BXpIOqspfthVlz6K33Q32i5iGYds9KZ5wwp7zNiuEC8axjwsr4uDdynt0dQhjNga-W1Zi3WRDQ3wIhdVWwooBCurXc1ykFXNOrarQJYiM7IFE5oUXc6XBrbzDluMxRSYgowvD-kP4eJBGj1Nl9tMNzznPF_zivEc-a82mwLPrKCuRFewSpEih73UZpVQpmBkvpkAt2Mf0Gl0iOHkRFF0bwGaOdUyOcbB-Sa2EhQmTDaRayZmfwBc3NWy">