https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122179

            Bug ID: 122179
           Summary: Creating iterator from auto typed VLA
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ellxor at proton dot me
  Target Milestone: ---

I am mostly a C programmer and was messing around to see what can be done in
C++ with VLA types. I'm sure this not allowed by C++, but should be handled
more gracefully.


Code that triggered bug:
```
// test.cc

auto& iterator_of_bytes(const char *data, int size) {
        return *(const char(*)[size])data;
}

int sum_bytes(const char *data, int size) {
        int sum = 0;

        for (char c : iterator_of_bytes(data,size)) {
                sum += c;
        }

        return sum;
}

```

GCC info:
```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-unknown-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /builddir/gcc-14.2.1+20250405/configure
--build=x86_64-unknown-linux-gnu --enable-gnu-unique-object
--enable-vtable-verify --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --libexecdir=/usr/lib64 --libdir=/usr/lib64
--enable-threads=posix --enable-__cxa_atexit --disable-multilib
--with-system-zlib --enable-shared --enable-lto --enable-plugins
--enable-linker-build-id --disable-werror --disable-nls --enable-default-pie
--enable-default-ssp --enable-checking=release --disable-libstdcxx-pch
--with-isl --with-linker-hash-style=gnu --disable-sjlj-exceptions
--disable-target-libiberty --disable-libssp
--enable-languages=c,c++,objc,obj-c++,fortran,lto,go,ada
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20250405 (GCC)
```

Compile command:
```
gcc -c test.cc
```

Compiler output:
```
during RTL pass: expand
test.cc: In function 'int sum_bytes(const char*, int)':
test.cc:8:50: internal compiler error: in expand_expr_real_1, at expr.cc:11376
    8 |         for (char c : iterator_of_bytes(data,size)) {
      |                                                  ^
0x7fa0be81abfb __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
0x7fa0be81acb4 __libc_start_main_impl
        ../csu/libc-start.c:360
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
```

It also produced the exact same error with GCC 15.2 which I don't have to hand
right now.

Reply via email to