https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122720
Bug ID: 122720
Summary: [Reflection] ICE with
std::meta::access_context::unchecked()
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bjorn.wehlin at gmail dot com
Target Milestone: ---
Created attachment 62823
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62823&action=edit
Output from compiling with -freport-bug
I'm trying out reflection on the branch mentioned at
https://gcc.gnu.org/pipermail/gcc-patches/2025-November/700733.html
Here's a minimal example that gives an ICE:
```
#include <meta>
#include <print>
struct S { int i; };
// Minified version of https://stackoverflow.com/a/79691381/2978125
(user:Barry)
template <typename T>
void bug(const T& v)
{
constexpr auto ctx = std::meta::access_context::unchecked();
template for (constexpr auto mem : define_static_array(
nonstatic_data_members_of(^^T, ctx)))
{
std::print(v.[:mem:]);
}
}
int main()
{
S s;
bug(s);
}
```
(The bug still occurs if struct S has no members, but I included `int i` to
illustrate the point.)
Compilation commandline: `g++ -std=c++26 -freflection -Wall -Wextra
-freport-bug bug.cpp`
Output of g++ -v -save-temps:
```
Using built-in specs.
COLLECT_GCC=/opt/gcc-trunk/bin/g++
COLLECT_LTO_WRAPPER=/opt/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --host=x86_64-pc-linux-gnu
--prefix=/opt/gcc-trunk --enable-threads=posix --disable-multilib
--disable-werror --enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20251114 (experimental) (GCC)
```
Output from `git rev-parse HEAD`: `e24623d67c8f7f0560478047d7503b3321e5136f`