This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Diagnose = delete override of a friend function defined earlier (PR c++/80259)


OK.

On Fri, Dec 1, 2017 at 7:13 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> As the testcase shows, we weren't diagnosing the foo case in the testcase
> and would just silently overwrite old DECL_INITIAL with error_mark_node
> and ICE later on.  Fixed thusly, bootstrapped/regtested on x86_64-linux
> and i686-linux, ok for trunk?
>
> 2017-12-01  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/80259
>         * decl2.c (grokfield): Diagnose = delete redefinition of a friend.
>
>         * g++.dg/cpp0x/pr80259.C: New test.
>
> --- gcc/cp/decl2.c.jj   2017-11-21 08:43:50.000000000 +0100
> +++ gcc/cp/decl2.c      2017-12-01 12:01:32.671514761 +0100
> @@ -911,9 +911,18 @@ grokfield (const cp_declarator *declarat
>         {
>           if (init == ridpointers[(int)RID_DELETE])
>             {
> -             DECL_DELETED_FN (value) = 1;
> -             DECL_DECLARED_INLINE_P (value) = 1;
> -             DECL_INITIAL (value) = error_mark_node;
> +             if (friendp && decl_defined_p (value))
> +               {
> +                 error ("redefinition of %q#D", value);
> +                 inform (DECL_SOURCE_LOCATION (value),
> +                         "%q#D previously defined here", value);
> +               }
> +             else
> +               {
> +                 DECL_DELETED_FN (value) = 1;
> +                 DECL_DECLARED_INLINE_P (value) = 1;
> +                 DECL_INITIAL (value) = error_mark_node;
> +               }
>             }
>           else if (init == ridpointers[(int)RID_DEFAULT])
>             {
> --- gcc/testsuite/g++.dg/cpp0x/pr80259.C.jj     2017-12-01 12:06:54.611405404 +0100
> +++ gcc/testsuite/g++.dg/cpp0x/pr80259.C        2017-12-01 12:06:19.000000000 +0100
> @@ -0,0 +1,13 @@
> +// PR c++/80259
> +// { dg-do compile { target c++11 } }
> +
> +void foo () {} // { dg-message "previously defined here" }
> +void bar ();
> +
> +struct A
> +{
> +  friend void foo () = delete; // { dg-error "redefinition of" }
> +  friend void bar () = delete; // { dg-message "previously defined here" }
> +};
> +
> +void bar () {} // { dg-error "redefinition of" }
>
>         Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]