https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124306
Bug ID: 124306
Summary: [reflection] internal compiler error: segmentation
fault when using meta::identifier_of
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: alexey.saldyrkine at gmail dot com
Target Milestone: ---
Created attachment 63797
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63797&action=edit
Preprocessed source
A segmentation fault occurs when calling meta::identifier_of with the return
value of meta::type_of for a templated function's parameter.
This only occurs with templated functions, not regular functions.
When the same code is used in a non-templated function, an exception is thrown,
as it probably should.
```
#include <meta>
namespace meta = std::meta;
using namespace std;
template<typename T>
void template_func(int a){
constexpr auto parameter_refl =
meta::parameters_of(^^template_func<int>)[0];
constexpr auto refl = meta::identifier_of(meta::type_of(parameter_refl));
\\ segfault here
}
void non_template_func(int a){
constexpr auto parameter_refl =
meta::parameters_of(^^non_template_func)[0];
constexpr auto refl = meta::identifier_of(meta::type_of(parameter_refl));
}
int main()
{
template_func<int>(1);
non_template_func(1);
return 0;
}
```
0x2963338 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x295807b internal_error(char const*, ...)
???:0
0xdf3182 process_metafunction(constexpr_ctx const*, tree_node*, tree_node*,
bool*, bool*, tree_node**)
???:0
0xb8f01c cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xdef980 process_metafunction(constexpr_ctx const*, tree_node*, tree_node*,
bool*, bool*, tree_node**)
???:0
0xb8f01c cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xba7dd9 maybe_constant_value(tree_node*, tree_node*, mce_value)
???:0
0xe75d27 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xc2e646 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
???:0
0xdcf6bd instantiate_decl(tree_node*, bool, bool)
???:0
0xdd91ba instantiate_pending_templates(int)
???:0
0xc42c48 c_parse_final_cleanups()
???:0
0xef6f28 c_common_parse_file()
???:0
Godbolt link: https://godbolt.org/z/PoszPebo7
## GCC Version, system, and options:
```
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/g++
Target: x86_64-linux-gnu
Configured with: ../gcc-trunk-20260226/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-6557358b399f813cf14a8b004862f6f86adc9392-binutils-2.44
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.1 20260226 (experimental)
(Compiler-Explorer-Build-gcc-6557358b399f813cf14a8b004862f6f86adc9392-binutils-2.44)
```
## Command line:
```
-quiet -v -imultiarch x86_64-linux-gnu -iprefix
/cefs/5b/5b7473000a337cbbdec6c161_gcc-trunk-20260226/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -Wall -Wextra -std=c++26
-version -fdiagnostics-color=always -fno-verbose-asm -freflection -o
/app/output.s
```