re PR c++/27100 (ICE with multiple friend declarations)
authorPatrick Palka <ppalka@gcc.gnu.org>
Fri, 3 Jun 2016 20:42:08 +0000 (20:42 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Fri, 3 Jun 2016 20:42:08 +0000 (20:42 +0000)
Fix PR c++/27100

gcc/cp/ChangeLog:

PR c++/27100
* decl.c (duplicate_decls): Properly copy the
DECL_PENDING_INLINE_P, DECL_PENDING_INLINE_INFO and
DECL_SAVED_FUNCTION_DATA fields from OLDDECL to NEWDECL.

gcc/testsuite/ChangeLog:

PR c++/27100
* g++.dg/other/friend6.C: New test.

From-SVN: r237078

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/friend6.C [new file with mode: 0644]

index bec708c9f817efa3b7e44199629e2c24cc606e80..0569d842e54006ab7d53c0eb787a6d6b198cd8bf 100644 (file)
@@ -1,3 +1,10 @@
+2016-06-03  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/27100
+       * decl.c (duplicate_decls): Properly copy the
+       DECL_PENDING_INLINE_P, DECL_PENDING_INLINE_INFO and
+       DECL_SAVED_FUNCTION_DATA fields from OLDDECL to NEWDECL.
+
 2016-06-03  Chung-Lin Tang  <cltang@codesourcery.com>
 
        * semantics.c (finish_omp_clauses): Mark OpenACC reduction
index cd7143b409cadbc4662ececedb92769d53ccb035..3328e7158aa4bd95e718f891aaa08ab4d5b51c70 100644 (file)
@@ -2351,8 +2351,17 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
        }
       else
        {
-         if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
-           DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
+         if (DECL_PENDING_INLINE_P (olddecl))
+           {
+             DECL_PENDING_INLINE_P (newdecl) = 1;
+             DECL_PENDING_INLINE_INFO (newdecl)
+               = DECL_PENDING_INLINE_INFO (olddecl);
+           }
+         else if (DECL_PENDING_INLINE_P (newdecl))
+           ;
+         else if (DECL_SAVED_FUNCTION_DATA (newdecl) == NULL)
+           DECL_SAVED_FUNCTION_DATA (newdecl)
+             = DECL_SAVED_FUNCTION_DATA (olddecl);
 
          DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
 
index ea1576b11ef171dd3e325b95e0ff8259420275e0..659477b8e7ea1c0a357e7b61ef0c98edb0614dc1 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-03  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/27100
+       * g++.dg/other/friend6.C: New test.
+
 2016-06-03  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        * g++.dg/torture/ppc-ldst-array.C: New.
diff --git a/gcc/testsuite/g++.dg/other/friend6.C b/gcc/testsuite/g++.dg/other/friend6.C
new file mode 100644 (file)
index 0000000..851cd25
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/27100
+// This used to fail at link time with an "undefined reference to 'foo'" error.
+// { dg-do run }
+
+struct A
+{
+  friend void foo (const A&) { }
+  friend void foo (const A&);
+};
+
+int
+main ()
+{
+  foo (A ());
+}