re PR c++/80259 (ICE deleting friend function)
authorJakub Jelinek <jakub@redhat.com>
Wed, 6 Dec 2017 22:48:39 +0000 (23:48 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 6 Dec 2017 22:48:39 +0000 (23:48 +0100)
PR c++/80259
* decl2.c (grokfield): Diagnose = delete redefinition of a friend.

* g++.dg/cpp0x/pr80259.C: New test.

From-SVN: r255456

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr80259.C [new file with mode: 0644]

index d8702e3bed98bc13c558be78807d79e849217809..9bfc72c361dcec2a7c4f723fc369e3875812ce5f 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/80259
+       * decl2.c (grokfield): Diagnose = delete redefinition of a friend.
+
 2017-12-06  Jason Merrill  <jason@redhat.com>
 
        * call.c (convert_for_arg_passing): Pass NULL_TREE to
index 13e7b1d180a8932c4b5e122ee0df6a79249877ab..2de36fa99bc5b10b265c4c331e6394a7266598ae 100644 (file)
@@ -911,9 +911,18 @@ grokfield (const cp_declarator *declarator,
        {
          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])
            {
index 176777e9d8326528e52c11ca4e0cbdebc06d8ae3..d7196733dd87e5db0b3478cc2ef1cefb61ec12cf 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/80259
+       * g++.dg/cpp0x/pr80259.C: New test.
+
 2017-12-06  David Malcolm  <dmalcolm@redhat.com>
 
        PR c/83236
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr80259.C b/gcc/testsuite/g++.dg/cpp0x/pr80259.C
new file mode 100644 (file)
index 0000000..9d2a109
--- /dev/null
@@ -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" }