OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Dec 2003 10:03:54 +0000 (10:03 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Dec 2003 10:03:54 +0000 (10:03 +0000)
PR c++/13242
C++ ABI change. Mangling template parameters of reference type
* mangle.c (write_template_args): Remove unreachable code.
(write_template_arg): Look through an argument of reference type.
testsuite:
PR c++/13242
* g++.dg/abi/mangle19-1.C: New test.
* g++.dg/abi/mangle19-2.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74682 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/mangle.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/abi/mangle19-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/abi/mangle19-2.C [new file with mode: 0644]

index f9de905..a04a3d3 100644 (file)
@@ -1,9 +1,16 @@
-2003-12-16  Giovanni Bajo  <giovannibajo@gcc.gnu.org>\r
-\r
-       PR c++/2294\r
-       * name-lookup.c (push_overloaded_decl): always construct an OVERLOAD\r
-       if the declaration comes from an using declaration.\r
-\r
+2003-12-16  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/13242
+       C++ ABI change. Mangling template parameters of reference type
+       * mangle.c (write_template_args): Remove unreachable code.
+       (write_template_arg): Look through an argument of reference type.
+
+2003-12-16  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/2294
+       * name-lookup.c (push_overloaded_decl): always construct an OVERLOAD
+       if the declaration comes from an using declaration.
+
 2003-12-15  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/10926
index a20757e..fe01120 100644 (file)
@@ -1845,37 +1845,25 @@ write_class_enum_type (const tree type)
 static void
 write_template_args (tree args)
 {
+  int i;
+  int length = TREE_VEC_LENGTH (args);
+  
   MANGLE_TRACE_TREE ("template-args", args);
 
   write_char ('I');
 
-  if (TREE_CODE (args) == TREE_VEC)
-    {
-      int i;
-      int length = TREE_VEC_LENGTH (args);
-      my_friendly_assert (length > 0, 20000422);
+  my_friendly_assert (length > 0, 20000422);
 
-      if (TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
-       {
-         /* We have nested template args.  We want the innermost template
-            argument list.  */
-         args = TREE_VEC_ELT (args, length - 1);
-         length = TREE_VEC_LENGTH (args);
-       }
-      for (i = 0; i < length; ++i)
-       write_template_arg (TREE_VEC_ELT (args, i));
-    }
-  else 
+  if (TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
     {
-      my_friendly_assert (TREE_CODE (args) == TREE_LIST, 20021014);
-
-      while (args)
-       {
-         write_template_arg (TREE_VALUE (args));
-         args = TREE_CHAIN (args);
-       }
+      /* We have nested template args.  We want the innermost template
+        argument list.  */
+      args = TREE_VEC_ELT (args, length - 1);
+      length = TREE_VEC_LENGTH (args);
     }
-
+  for (i = 0; i < length; ++i)
+    write_template_arg (TREE_VEC_ELT (args, i));
+  
   write_char ('E');
 }
 
@@ -2165,6 +2153,20 @@ write_template_arg (tree node)
          code = TREE_CODE (node);
        }
     }
+  
+  if (TREE_CODE (node) == NOP_EXPR
+      && TREE_CODE (TREE_TYPE (node)) == REFERENCE_TYPE)
+    {
+      /* Template parameters can be of reference type. To maintain
+        internal consistency, such arguments use a conversion from
+        address of object to reference type.  */
+      my_friendly_assert (TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR,
+                         20031215);
+      if (abi_version_at_least (2))
+       node = TREE_OPERAND (TREE_OPERAND (node, 0), 0);
+      else
+       G.need_abi_warning = 1;
+    }
 
   if (TYPE_P (node))
     write_type (node);
index 2cfbebd..496737d 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-16  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/13242
+       * g++.dg/abi/mangle19-1.C: New test.
+       * g++.dg/abi/mangle19-2.C: New test.
+
 2003-12-16  Hartmut Penner  <hpenner@de.ibm.com>
 
        * testsuite/gcc.dg/altivec-10.c: Test vec_cmple and vec_all_numeric.
diff --git a/gcc/testsuite/g++.dg/abi/mangle19-1.C b/gcc/testsuite/g++.dg/abi/mangle19-1.C
new file mode 100644 (file)
index 0000000..7cc946e
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-fabi-version=2" }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 15 Dec 2003 <nathan@codesourcery.com>
+
+// PR 13242
+// mangled template arguments that are external objects incorrectly
+
+extern int N;
+template <int &> struct S {};
+void n (S<N>) {}
+// { dg-final { scan-assembler "\n_Z1n1SILZ1NEE:" } }
diff --git a/gcc/testsuite/g++.dg/abi/mangle19-2.C b/gcc/testsuite/g++.dg/abi/mangle19-2.C
new file mode 100644 (file)
index 0000000..fbf1a07
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-fabi-version=1 -Wabi" }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 15 Dec 2003 <nathan@codesourcery.com>
+
+// PR 13242
+// mangled template arguments that are external objects incorrectly
+
+extern int N;
+template <int &> struct S {};
+void n (S<N>) {}  // { dg-warning "mangled name" }
+// { dg-final { scan-assembler "\n_Z1n1SIXadL_Z1NEEE:" } }