| Issue |
240957
|
| Summary |
template for does not do anything in one specific situation and crashes in another
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
misos1
|
Test1 should print "2 2" because it should do `a[0] = a[1]` but it prints "1 2" instead. Test2 causes a crash. When the line with `using Array = ...` is changed to `using Array = std::array<int, size<0>>;` then it behaves as expected.
Ubuntu clang version 24.0.0
``` c++
#include <array>
#include <cstdio>
template<int>
constexpr int size = 2;
template<int I>
struct A
{
using Array = std::array<int, size<I>>;
static void test1(Array a)
{
template for(constexpr int i : {0})
{
a[i] = a[i + 1];
}
printf("%i %i\n", a[0], a[1]); // still 1 2
}
static void test2(Array &a)
{
template for(constexpr int i : {0})
{
a[i] = a[i + 1]; // SIGSEGV
}
}
};
int main()
{
std::array<int, 2> a = {1, 2};
A<0>::test1(a);
A<0>::test2(a);
}
```
```
clang++-24 -std=c++26 -g a.cpp && ./a.out
```
```
1 2
Segmentation fault (core dumped) ./a.out
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs