https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126657
Bug ID: 126657
Summary: ICE in reflection metafunctions when a custom, invalid
definition of std::meta::exception is provided
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: programmer00001h at gmail dot com
Target Milestone: ---
Created attachment 65244
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65244&action=edit
output of -freport-bug
In a similar fashion to PR125647 and PR125732, a bad custom definition of
std::meta::exception is also capable of crashing the compiler:
#include<ranges>
namespace std::meta{
using info = decltype(^^::);
struct exception{
exception(auto...){}
};
template<typename _Rg = initializer_list<info>>
consteval info substitute(info, _Rg&&);
}
template<typename T>
struct tpl{};
int main(){
substitute(^^tpl,{^^tpl});
return 0;
}
When compiled as g++ -std=c++26 -freflection ice.cpp, this will cause the
following crash:
ice.cpp: In function ‘int main()’:
ice.cpp:13:15: internal compiler error: Segmentation fault
13 | substitute(^^tpl,{^^tpl});
| ~~~~~~~~~~^~~~~~~~~~~~~~~
0x2815a98 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x28180a7 internal_error(char const*, ...)
???:0
0x78ca97 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0x78d422 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0x152d669 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
???:0
0x152da04 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
???:0
0x7c2238 cp_fold_function(tree_node*)
???:0
0x812a0c finish_function(bool)
???:0
0xaa51c0 c_common_parse_file()
???:0
Output of gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-gcc-major-version-only
--with-linker-hash-style=gnu --with-system-zlib --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-fixincludes --disable-libssp
--disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.1.1 20260728 (GCC)