<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71888>71888</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
issue compiling codes with large constexpr arrays of function pointers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
rejects-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wheatman
</td>
</tr>
</table>
<pre>
I am trying to make some large constexpr arrays of functions pointers, but when they get to a certain size they just seem to break and starts giving error messages about parts of the code which doesn't change with the size.
The code can be found at
working with a size of `1<<15`
https://godbolt.org/z/15badTccs
broken with a size of `1<<16`
https://godbolt.org/z/KMPGYbKcx
The code has been simplified down to
```
#include <array>
#include <type_traits>
template <int enabled_blocks>
static void foo() {
return;
}
using fn_type = void();
template <std::size_t... I>
constexpr auto static make_helper(std::index_sequence<I...>) {
return std::array<fn_type *, sizeof...(I)>{foo<I>...};
}
template <std::size_t MAX> static constexpr auto get_foos() {
return make_helper(std::make_index_sequence<MAX>{});
}
static constexpr int num = 1UL << 15; // it no longer compiles if this is changed to 16
static constexpr std::array<fn_type *, num> foos =
get_foos<num>();
int main(int argc, char *argv[]) {
foos[argc]();
return 0;
}
```
The error with the code that has 16 instead of 15 is
```
<source>:17:48: error: initializer for aggregate with no elements requires explicit braces
17 | return std::array<fn_type *, sizeof...(I)>{foo<I>...};
| ^
<source>:20:12: note: in instantiation of function template specialization 'make_helper<0UL, 1UL, 2UL, 3UL, 4UL,
...
...
65530UL, 65531UL, 65532UL, 65533UL, 65534UL, 65535UL>' requested here
20 | return make_helper(std::make_index_sequence<MAX>{});
| ^
<source>:26:7: note: in instantiation of function template specialization 'get_foos<65536UL>' requested here
26 | get_foos<num>();
| ^
1 error generated.
Compiler returned: 1
```
I first guessed the issue had to do with one of the limits here https://clang.llvm.org/docs/UsersManual.html#controlling-implementation-limits
However, all but `constexpr-steps` seem to small to be related and I tried increasing it with `-fconstexpr-steps=134217728` and it had no effect
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk1v2zgQ_TX0ZRBDIi3JPvjgOMlu0BbYQwPsngJKGklsKNIlqXz01y-Gkj-SuM0eukEgEdZw5r03nOFI71VrENcsu2TZ1UwOobNu_dShDL00s9LWL-tbkD0E96JMC8FCLx8QvO0RtHQtQmWND_i8cyCdky8ebAPNYKqgrPGws8oEdJ7xLZRDgKcODYQOX6DFQO4kVOiCVAa8-oHjp2-DD-ARezIoHcoHkKYGH6QLHlr1SFDQOeugR-9lix5kaYcAu2hhG_IDla0RnjpVdVBb9IbxIkDVSdMiPKnQRSOKOmfJFUs24_PrfmclDZQIjR1MDTLAqdGTdQ8EIrqRI3TbAMuTlIktE9s0Y3ky2nYh7DwTG8ZvGL9pbV1aHebWtYzf_GD8Js1KWX-tKn8aoHT2Ac0v_Of_2f-nL3_98U_5qXo-y7KTHkpEkr_fadUorKG2TwaCnezzZPo_2c64UKbSQ43AxDYmnonrc9_Cyw7vg5Mq-KPFuydAwH6nZYh7lAmARpYa6_tS2-rhuBXoFARVwaNVNTTWMr5kfAWsuNwbADgMgzNMHH5ixdW5mIOnHDbmnkACE1fR6-jxsHsyPsXnQ016iw3l5T7M53O4PUF4UhFDsHvAVDf3HeodOsaXBxfK1Ph87_H7gKZCJra38_mcnJ0nBYeNk-jbA3y-oSIjSLYhH3x5G3lcs-KShBJbAklfiqtz2sCvOMKXzd9MXO_JvKHYYrhvrPU_T8bP6Mef32kwBiM3xdVpLt5lEt4DosNjhj6mM737DGO9QJoxcQkwFgmoAMaCtqZFB5Xtd0qjB0V9Q3lQfmoTNTWgNP8g4kcpMUNP0pFAhGryc9BMbEeDs-fu_ZP49VIZxpe0lK6tKEjVSUcBpWsfx27-KhN78DFidhl3kcnytbxTspIjioPe59oAdZGxDx_6aWwqoZMhdpY0B0UyyZraV5qB8ufdia23g6PkXzOxSQsmNoslE5vRPS2UUUFJrX6gg8Y6kG3rsKXTGmMbC6ixR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