* [C++ PATCH] Diagnose = delete override of a friend function defined earlier (PR c++/80259)
@ 2017-12-02 0:13 Jakub Jelinek
2017-12-06 22:37 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-12-02 0:13 UTC (permalink / raw)
To: Jason Merrill, Nathan Sidwell; +Cc: gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Diagnose = delete override of a friend function defined earlier (PR c++/80259)
2017-12-02 0:13 [C++ PATCH] Diagnose = delete override of a friend function defined earlier (PR c++/80259) Jakub Jelinek
@ 2017-12-06 22:37 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2017-12-06 22:37 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Nathan Sidwell, gcc-patches List
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-06 22:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-02 0:13 [C++ PATCH] Diagnose = delete override of a friend function defined earlier (PR c++/80259) Jakub Jelinek
2017-12-06 22:37 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).