https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95820

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>:

https://gcc.gnu.org/g:9eb370f19c1198e62d47eae74531e54d0b098bf1

commit r11-2085-g9eb370f19c1198e62d47eae74531e54d0b098bf1
Author: Marek Polacek <pola...@redhat.com>
Date:   Wed Jun 24 17:39:21 2020 -0400

    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.

Reply via email to