]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Improve checking of decls with trailing return type [PR95820]
authorMarek Polacek <polacek@redhat.com>
Wed, 24 Jun 2020 21:39:21 +0000 (17:39 -0400)
committerGiuliano Belinassi <giuliano.belinassi@usp.br>
Mon, 17 Aug 2020 16:17:40 +0000 (13:17 -0300)
commitecf0acc9ab98bd25fa1aec5634b6deab71d6cafd
tree507c22b948a482459814b5ac7ab3153e0f683c01
parent4eb2863006346a4ef1edd97772672e2abef04479
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.
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp1y/auto-fn58.C [new file with mode: 0644]