| Issue |
173949
|
| Summary |
`error: initializer for aggregate with no elements requires explicit braces` or `error: excess elements in struct initializer` in clang++ with more than 32767 elements
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
user202729
|
Consider the following code
```cpp
#include<ranges>
#include<vector>
template <auto f>
inline auto constexpr MakeConstexprArray()
{
auto result = f();
return (([&]<std::size_t... Indices>(std::index_sequence<Indices...>)
{
return std::array<typename decltype(result)::value_type, sizeof...(Indices)>{result[Indices]...};
})(std::make_index_sequence<f().size()>()));
}
static constexpr auto x = MakeConstexprArray<[]{ return std::views::iota(0, 32768) | std::ranges::to<std::vector>(); }>();
int main() {}
```
Compile with `clang++ -fconstexpr-steps=1271242 -std=c++23 a.cpp`, I get
```
a.cpp:10:88: error: initializer for aggregate with no elements requires
explicit braces
10 | return std::array<typename decltype(result)::value_type, sizeof...(Indices)>{resul
...
| ^
a.cpp:8:13: note: in instantiation of function template specialization
```
if I change `32768` to `32769`, I get
```
a.cpp:10:88: error: excess elements in struct initializer
10 | ...std::array<typename decltype(result)::value_type, sizeof...(Indices)>{result[Indices]..
.};
| ^~~~~~~~~~~~~~~
a.cpp:8:13: note: in instantiation of function template specialization
```
on the other hand, we probably don't want to slow down code that uses ≤ 32767 elements by using a larger data type or bound-check every addition.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs