https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114911
Bug ID: 114911 Summary: Anonymous unions can cause ICE when the name of their type escapes Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: ice-checking, ice-on-valid-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` void g(); template<typename T> struct Capture; template<typename T> struct Capture<T*> { friend void g() { &T::a; } }; struct X; void f() { union { int a = sizeof(Capture<decltype(this)>); }; g(); } ``` GCC ICEs with: ``` <source>: In instantiation of 'void g()': <source>:19:6: required from here 19 | g(); | ~^~ <source>:9:9: internal compiler error: tree check: expected class 'type', have 'declaration' (function_decl) in build_offset_type, at tree.cc:7718 9 | &T::a; | ^~~~~ 0x267adac internal_error(char const*, ...) ???:0 0x966cd9 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*) ???:0 0xd20f91 build_x_unary_op(unsigned int, tree_code, cp_expr, tree_node*, int) ???:0 0xc95413 instantiate_decl(tree_node*, bool, bool) ???:0 0xcbeb3b instantiate_pending_templates(int) ???:0 0xb59819 c_parse_final_cleanups() ???:0 0xdb2668 c_common_parse_file() ???:0 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. ``` Note this is the same testcase as the clang bug: https://github.com/llvm/llvm-project/issues/90751 just that GCC ICEs too. Note also this seems not to ICE with release checking .