c++: ICE with operator delete [PR104846]
authorMarek Polacek <polacek@redhat.com>
Wed, 9 Mar 2022 16:23:15 +0000 (11:23 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 10 Mar 2022 14:31:34 +0000 (09:31 -0500)
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.

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
gcc/testsuite/g++.dg/init/delete5.C [new file with mode: 0644]

index 37d52d8..c42be60 100644 (file)
@@ -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 (file)
index 0000000..3555f43
--- /dev/null
@@ -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'" }
+};
+