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

            Bug ID: 123726
           Summary: [C++26] ICE in template for with reflection on local
                    struct
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: greis.sebastian at yahoo dot de
  Target Milestone: ---

Created attachment 63424
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63424&action=edit
Minimal reproduction case

System: Godbolt x86-64 (trunk) (https://godbolt.org/z/4GGzvej5h)
GCC Version: gcc version 16.0.1 20260119 (experimental)
Command line options: -std=c++2c -freflection -Wall -Wextra -freport-bug -v

The following minimal C++ code triggers an Internal Compiler Error (ICE) in the
GCC development trunk. The crash occurs when attempting to use a template for
loop to iterate over a struct's members using reflection.

Expected Results:
The compiler should either compile the code successfully or provide a standard
diagnostic error message if the reflection syntax is used incorrectly, but it
should not crash.

Compiler output:
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/g++
COLLECT_LTO_WRAPPER=/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../libexec/gcc/x86_64-linux-gnu/16.0.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../gcc-trunk-20260119/configure
--prefix=/opt/compiler-explorer/gcc-build/staging --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu
--enable-languages=c,c++,fortran,ada,objc,obj-c++,go,d,rust,m2,cobol,algol68
--enable-ld=yes --enable-gold=yes --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build-gcc-80434bcc5d96333b4164aa817069aec8a8290920-binutils-2.44
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.1 20260119 (experimental)
(Compiler-Explorer-Build-gcc-80434bcc5d96333b4164aa817069aec8a8290920-binutils-2.44)
 
COLLECT_GCC_OPTIONS='-fdiagnostics-color=always' '-g' '-o' '/app/output.s'
'-fno-verbose-asm' '-std=c++26' '-freflection' '-Wall' '-Wextra' '-freport-bug'
'-v' '-L./lib' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir'
'/app/output.s-'

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../libexec/gcc/x86_64-linux-gnu/16.0.1/cc1plus
-quiet -v -imultiarch x86_64-linux-gnu -iprefix
/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/output.s- -dumpbase example.cpp
-dumpbase-ext .cpp -mtune=generic -march=x86-64 -g -Wall -Wextra -std=c++26
-version -fdiagnostics-color=always -fno-verbose-asm -freflection -freport-bug
-o /tmp/ccGRqYrz.s
GNU C++26
(Compiler-Explorer-Build-gcc-80434bcc5d96333b4164aa817069aec8a8290920-binutils-2.44)
version 16.0.1 20260119 (experimental) (x86_64-linux-gnu)
        compiled by GNU C version 11.4.0, GMP version 6.3.0, MPFR version
4.2.2, MPC version 1.3.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../x86_64-linux-gnu/include"
ignoring duplicate directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../include/c++/16.0.1"
ignoring duplicate directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../include/c++/16.0.1/x86_64-linux-gnu"
ignoring duplicate directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../include/c++/16.0.1/backward"
ignoring duplicate directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/16.0.1/include"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring duplicate directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/16.0.1/include-fixed/x86_64-linux-gnu"
ignoring duplicate directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/16.0.1/include-fixed"
ignoring nonexistent directory
"/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../include/c++/16.0.1

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../include/c++/16.0.1/x86_64-linux-gnu

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/../../../../include/c++/16.0.1/backward

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/include

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/include-fixed/x86_64-linux-gnu

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/include-fixed
 /usr/local/include

/cefs/87/87a6e0c01e4652c9cb06068d_gcc-trunk-20260119/bin/../lib/gcc/../../include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
Compiler executable checksum: 061e1deea1d1b9f59d8e07e10aa3ef35
<source>: In instantiation of 'template for' iteration 1:
required from here
<source>:10:30:   
   10 |     template for (const auto m : d) {
      |                              ^
<source>:11:18: internal compiler error: in finish_class_member_access_expr, at
cp/typeck.cc:3651
   11 |         d.[: ^^m :] = 5;
      |         ~~~~~~~~~^~
0x2950b58 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x294591b internal_error(char const*, ...)
        ???:0
0xb1ec72 fancy_abort(char const*, int, char const*)
        ???:0
0xdc4768 finish_expansion_stmt(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd64c43 c_parse_file()
        ???:0
0xeeed69 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Preprocessed source stored into /tmp/cczupzSU.out file, please attach this to
your bugreport.
Compiler returned: 1

Disclaimer: This is my first bug report and to improve readability I used
Gemini  3 Flash (LLM/AI) to create the summary and part of the description. I
hope you don't mind. I'm only a C++ hobbyist, so I might not be able to answer
in-depth question very well. But I'll do my best.

Best regards,

Sebastian Greis
  • [Bug c++/123726] New: [C++26]... greis.sebastian at yahoo dot de via Gcc-bugs

Reply via email to