Repository navigation
Reflection: assignment to a default-initialized local reflection fails with "attempt to access run-time storage" #177
Closed
stevensudit-corvid
started this conversation in
Issue Triage - Compilation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Issue Summary
With the experimental reflection support enabled, a
constevalfunction cannot assign to a local variable of reflection type that was declared without an initializer. Constant evaluation stops at the assignment with "attempt to access run-time storage". I understand reflection is still experimental; this looks like a small gap in it.gcc accepts the code with
-freflection. I ran into it in aconstevalhelper that declares astd::meta::infoand then assigns it in each branch of anif.Reproducing Source Code
Command-line Options
cpfe --c++26 repro.cpp
Type of Issue
[Front End] This code SHOULD compile with these options.
Additional Details
The diagnostic, at 158320e (version 7.0), in the
linux-gcc-reflection-releaseconfiguration:With gcc 16's
<meta>in the GNU mode, a localstd::meta::infobehaves the same way.Any one of these changes makes it compile:
info r{};orinfo r = info{};.consteval info f() { info r; return r; }compiles, and the result compares equal toinfo{}.int, a pointer ordecltype(nullptr)compiles.new info.It still fails when the variable is assigned and never read, when it is in a nested block, and for an element of
info r[1];.Reading the source, three places seem to combine into this:
def_initializergives a default-initialized variable of reflection typeinit_kind = initk_zero(decl_inits.c:7353, "Default-initialization for reflection types is zero-initialization").init_kind == initk_none(interpret.c:8452), so this variable gets no storage. In a debug build, theinit_kindat that line isinitk_zeroforinfo r;andinitk_noneforint r;.eok_assigncase has no counterpart, finds a run-time address as its destination, and reports it (interpret.c:30229).Reproducing (Standard) Configuration(s)
linux-gcc-reflection-release
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.All reactions