[Bug c++/126154] New: [reflection] Internal compiler error with reflection of static local object containing pointer-to-self within template: in discriminator_for_local_entity, at cp/mangle.cc:2337

friedkeenan at protonmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jul 7 17:59:31 GMT 2026


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

            Bug ID: 126154
           Summary: [reflection] Internal compiler error with reflection
                    of static local object containing pointer-to-self
                    within template: in discriminator_for_local_entity, at
                    cp/mangle.cc:2337
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: friedkeenan at protonmail dot com
  Target Milestone: ---

The erroring code:
```
#include <meta>

struct self_reference {
    const self_reference *self = this;
};

template<typename>
void function() {
    static constexpr auto SelfReferencing = self_reference{};

    constexpr auto _ = std::meta::reflect_constant(SelfReferencing);
}
```

Godbolt link: https://godbolt.org/z/chv8q7478

On current trunk, this results in the following error:
```
<source>: In function 'void function()':
<source>:11:51: internal compiler error: in discriminator_for_local_entity, at
cp/mangle.cc:2337
   11 |     constexpr auto _ = std::meta::reflect_constant(SelfReferencing);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
0x2b1b668 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x2b102ab internal_error(char const*, ...)
        ???:0
0xb394a0 fancy_abort(char const*, int, char const*)
        ???:0
0xca6be7 mangle_template_parm_object(tree_node*)
        ???:0
0xdc1c6c convert_reflect_constant_arg(tree_node*, tree_node*)
        ???:0
0xe174ec process_metafunction(constexpr_ctx const*, tree_node*, tree_node*,
bool*, bool*, tree_node**)
        ???:0
0xba6f27 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
        ???:0
0xb72307 build_new_function_call(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0xe2f745 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd8d063 c_parse_file()
        ???:0
0xf1dc39 c_common_parse_file()
        ???:0
```

This code compiles successfully on 16.1.1. It also compiles successfully on
trunk if one changes `function` to not be a template function.

This issue would appear to me very similar to Bug 124824, though that is still
fixed in trunk for the code which caused that bug.


More information about the Gcc-bugs mailing list