* [PATCH] c++: fix ICE with xobj in destructor [PR113340]
@ 2024-01-16 21:28 Marek Polacek
2024-01-16 22:03 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2024-01-16 21:28 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
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 <T8d> (void)
and crashing on
parms = DECL_CHAIN (DECL_ARGUMENTS (fn));
This patch avoid the ICE by resetting is_xobj_member_function after
emitting the error. Then m_r_in_c gets
void S::<T40b> (struct S *)
which does not cause a crash.
PR c++/113340
gcc/cp/ChangeLog:
* decl.cc (grokdeclarator) <case cdk_function>: Clear
is_xobj_member_function in case of an error.
gcc/testsuite/ChangeLog:
* g++.dg/cpp23/explicit-obj-diagnostics9.C: New test.
---
gcc/cp/decl.cc | 1 +
gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics9.C | 6 ++++++
2 files changed, 7 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics9.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index b10a72a87bf..2e5702971c4 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 00000000000..d420793c1e1
--- /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" }
+};
base-commit: 6a6f338c1cbfc2585cd85358a83e601fb959445e
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: fix ICE with xobj in destructor [PR113340]
2024-01-16 21:28 [PATCH] c++: fix ICE with xobj in destructor [PR113340] Marek Polacek
@ 2024-01-16 22:03 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-01-16 22:03 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 1/16/24 16:28, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK.
> -- >8 --
> 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 <T8d> (void)
> and crashing on
> parms = DECL_CHAIN (DECL_ARGUMENTS (fn));
>
> This patch avoid the ICE by resetting is_xobj_member_function after
> emitting the error. Then m_r_in_c gets
> void S::<T40b> (struct S *)
> which does not cause a crash.
>
> PR c++/113340
>
> gcc/cp/ChangeLog:
>
> * decl.cc (grokdeclarator) <case cdk_function>: Clear
> is_xobj_member_function in case of an error.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp23/explicit-obj-diagnostics9.C: New test.
> ---
> gcc/cp/decl.cc | 1 +
> gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics9.C | 6 ++++++
> 2 files changed, 7 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics9.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index b10a72a87bf..2e5702971c4 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 00000000000..d420793c1e1
> --- /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" }
> +};
>
> base-commit: 6a6f338c1cbfc2585cd85358a83e601fb959445e
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-16 22:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 21:28 [PATCH] c++: fix ICE with xobj in destructor [PR113340] Marek Polacek
2024-01-16 22:03 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).