public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE with operator delete [PR104846]
@ 2022-03-09 18:09 Marek Polacek
  2022-03-10  4:18 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2022-03-09 18:09 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

This is an ICE-on-invalid with "auto operator delete[] (void *)" whose
return type must be void.  The return type is checked in coerce_delete_type
but we never got there in this test, because we took the wrong path in
grokdeclarator, set type to error_mark_node, ended up creating a FIELD_DECL
with build_decl, and confused grokmethod by giving it a FIELD_DECL.

Fixed by not taking the data member path for a FUNCTION_TYPE.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

	PR c++/104846

gcc/cp/ChangeLog:

	* decl.cc (grokdeclarator): Check FUNC_OR_METHOD_TYPE_P before giving
	data member errors.

gcc/testsuite/ChangeLog:

	* g++.dg/init/delete5.C: New test.
---
 gcc/cp/decl.cc                      | 2 +-
 gcc/testsuite/g++.dg/init/delete5.C | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/init/delete5.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 992e38385c2..12f2524aafe 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -13751,7 +13751,7 @@ grokdeclarator (const cp_declarator *declarator,
       }
     else if (decl_context == FIELD)
       {
-	if (!staticp && !friendp && TREE_CODE (type) != METHOD_TYPE)
+	if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
 	  if (tree auto_node = type_uses_auto (type))
 	    {
 	      location_t tloc = declspecs->locations[ds_type_spec];
diff --git a/gcc/testsuite/g++.dg/init/delete5.C b/gcc/testsuite/g++.dg/init/delete5.C
new file mode 100644
index 00000000000..3555f43bbb0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/delete5.C
@@ -0,0 +1,8 @@
+// PR c++/104846
+// { dg-do compile { target c++14 } }
+
+struct S {
+  auto operator delete (void *) {} // { dg-error ".operator delete. must return type .void'" }
+  auto operator delete[] (void *) {} // { dg-error ".operator delete. must return type .void'" }
+};
+

base-commit: bded0d549fdfdc1328b2c0189dc5f8593b4cbe42
-- 
2.35.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-10  4:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09 18:09 [PATCH] c++: ICE with operator delete [PR104846] Marek Polacek
2022-03-10  4:18 ` 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).