From: Marek Polacek Date: Tue, 16 Jan 2024 20:49:46 +0000 (-0500) Subject: c++: fix ICE with xobj in destructor [PR113340] X-Git-Tag: basepoints/gcc-15~1974 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac219d524ace47eea5bf5404b267e22950f44030;p=thirdparty%2Fgcc.git c++: fix ICE with xobj in destructor [PR113340] Here we crash in maybe_retrofit_in_chrg on an invalid dtor with explicit this. Such member functions do not get converted to METHOD_TYPE. If a dtor gets parameters, we reset arg_types to void_list_node in grokdeclarator. This results in m_r_in_c receiving: void (void) and crashing on parms = DECL_CHAIN (DECL_ARGUMENTS (fn)); This patch avoids the ICE by resetting is_xobj_member_function after emitting the error. Then m_r_in_c gets void S:: (struct S *) which does not cause a crash. PR c++/113340 gcc/cp/ChangeLog: * decl.cc (grokdeclarator) : Clear is_xobj_member_function in case of an error. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-diagnostics9.C: New test. --- diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index b10a72a87bf0..2e5702971c4c 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -13743,6 +13743,7 @@ grokdeclarator (const cp_declarator *declarator, "destructors may not have parameters"); arg_types = void_list_node; parms = NULL_TREE; + is_xobj_member_function = false; } type = build_function_type (type, arg_types); diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics9.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics9.C new file mode 100644 index 000000000000..d420793c1e1a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics9.C @@ -0,0 +1,6 @@ +// PR c++/113340 +// { dg-do compile { target c++23 } } + +struct S { + ~S(this S &) = default; // { dg-error "destructors may not have parameters" } +};