c++: Improve checking of decls with trailing return type [PR95820]
This is an ICE-on-invalid but I've been seeing it when reducing
various testcases, so it's more important for me than usually.
splice_late_return_type now checks that if we've seen a late return
type, the function return type was auto. That's a fair assumption
but grokdeclarator/cdk_function wasn't giving errors for function
pointers and similar. So we want to perform various checks not only
when funcdecl_p || inner_declarator == NULL. But only give the
!late_return_type errors when funcdecl_p, to accept e.g.
auto (*fp)() = f;
in C++11. Here's a diff -w to ease the review:
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12102,14 +12102,9 @@ grokdeclarator (const cp_declarator *declarator,
/* Handle a late-specified return type. */
tree late_return_type = declarator->u.function.late_return_type;
- if (funcdecl_p
- /* This is the case e.g. for
- using T = auto () -> int. */
- || inner_declarator == NULL)
- {
if (tree auto_node = type_uses_auto (type))
{
- if (!late_return_type)
+ if (!late_return_type && funcdecl_p)
{
if (current_class_type
&& LAMBDA_TYPE_P (current_class_type))
@@ -12201,7 +12196,6 @@ grokdeclarator (const cp_declarator *declarator,
"type specifier", name);
return error_mark_node;
}
- }
type = splice_late_return_type (type, late_return_type);
if (type == error_mark_node)
return error_mark_node;
gcc/cp/ChangeLog:
PR c++/95820
* decl.c (grokdeclarator) <case cdk_function>: Check also
pointers/references/... to functions.
gcc/testsuite/ChangeLog:
PR c++/95820
* g++.dg/cpp1y/auto-fn58.C: New test.