https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118192
Bug ID: 118192 Summary: ICE: in build_data_member_initialization, at cp/constexpr.cc:453 Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wangbopku15 at gmail dot com Target Milestone: --- The following invalid code triggers an ICE on x86-64 gcc trunk: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template<int> struct base { int y; base() = delete; constexpr base(int a) : base{} { y = a; } }; struct foo : base<1> { constexpr foo(int a) : base<1>{a} { } }; int main() { constexpr foo bar1{1}; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's invalid because the ` constexpr base(int a) : base{}` tries to call the deleted default ctor of `base`. Please note that the crash will not appear if the ctor does nothing in its function body like: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template<int> struct base { base() = delete; constexpr base(int a) : base{}{} }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please check https://godbolt.org/z/8Pj76MdoT for more information. $ g++ -freport-bug of3468.cpp <source>: In instantiation of 'constexpr base<<anonymous> >::base(int) [with int <anonymous> = 1]': <source>:12:35: required from here 12 | constexpr foo(int a) : base<1>{a} | ^ <source>:19:23: in 'constexpr' expansion of '((foo*)(& bar1))->foo::foo(1)' <source>:6:32: error: use of deleted function 'base<<anonymous> >::base() [with int <anonymous> = 1]' 6 | constexpr base(int a) : base{} | ^ <source>:5:3: note: declared here 5 | base() = delete; | ^~~~ <source>:6:32: note: use '-fdiagnostics-all-candidates' to display considered candidates 6 | constexpr base(int a) : base{} | ^ <source>: In function 'int main()': <source>:19:23: in 'constexpr' expansion of '((foo*)(& bar1))->foo::foo(1)' <source>:12:35: error: 'constexpr base<<anonymous> >::base(int) [with int <anonymous> = 1]' called in a constant expression 12 | constexpr foo(int a) : base<1>{a} | ^ <source>:6:13: note: 'constexpr base<<anonymous> >::base(int) [with int <anonymous> = 1]' is not usable as a 'constexpr' function because: 6 | constexpr base(int a) : base{} | ^~~~ <source>:6:13: internal compiler error: in build_data_member_initialization, at cp/constexpr.cc:453 0x2931885 diagnostic_context::diagnostic_impl(rich_location*, diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag (*) [1], diagnostic_t) ???:0 0x2948656 internal_error(char const*, ...) ???:0 0xac9dee fancy_abort(char const*, int, char const*) ???:0 0xb42a60 explain_invalid_constexpr_fn(tree_node*) ???:0 0xdc5bde store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ???:0 0xbbeb4e cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int, cp_decomp*) ???:0 0xce1f2a c_parse_file() ???:0 0xe41159 c_common_parse_file() ???:0 Please submit a full bug report, with preprocessed source. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.