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.
}
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];
--- /dev/null
+// 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'" }
+};
+