re PR c++/48008 (libstdc++-v3/testsuite/20_util/function/43397.cc fails to assemble...
authorJason Merrill <jason@redhat.com>
Mon, 7 Mar 2011 20:10:44 +0000 (15:10 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 7 Mar 2011 20:10:44 +0000 (15:10 -0500)
PR c++/48008
* mangle.c (write_type): Strip cv-quals from FUNCTION_TYPE here.
(write_CV_qualifiers_for_type): Not here.

From-SVN: r170752

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

index 3e228b0395c3fb6000eeef7bec6cc19b57f18d2e..03fe7def98315a300234251f4298e5174894ba20 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-07  Jason Merrill  <jason@redhat.com>
+
+       PR c++/48008
+       * mangle.c (write_type): Strip cv-quals from FUNCTION_TYPE here.
+       (write_CV_qualifiers_for_type): Not here.
+
 2011-03-06  Joseph Myers  <joseph@codesourcery.com>
 
        * lang-specs.h: Match -save-temps* instead of -save-temps.
index 0297a2adc5835207e628948b59f964ec8630c082..c46ba305def371ae6acddbac7982f059821f95fb 100644 (file)
@@ -1880,16 +1880,25 @@ write_type (tree type)
              break;
 
            case POINTER_TYPE:
-             write_char ('P');
-             write_type (TREE_TYPE (type));
-             break;
-
            case REFERENCE_TYPE:
-             if (TYPE_REF_IS_RVALUE (type))
-               write_char('O');
+             if (TREE_CODE (type) == POINTER_TYPE)
+               write_char ('P');
+             else if (TYPE_REF_IS_RVALUE (type))
+               write_char ('O');
               else
                 write_char ('R');
-             write_type (TREE_TYPE (type));
+             {
+               tree target = TREE_TYPE (type);
+               /* Attribute const/noreturn are not reflected in mangling.
+                  We strip them here rather than at a lower level because
+                  a typedef or template argument can have function type
+                  with function-cv-quals (that use the same representation),
+                  but you can't have a pointer/reference to such a type.  */
+               if (abi_version_at_least (5)
+                   && TREE_CODE (target) == FUNCTION_TYPE)
+                 target = build_qualified_type (target, TYPE_UNQUALIFIED);
+               write_type (target);
+             }
              break;
 
            case TEMPLATE_TYPE_PARM:
@@ -2017,12 +2026,6 @@ write_CV_qualifiers_for_type (const tree type)
      array.  */
   cp_cv_quals quals = TYPE_QUALS (type);
 
-  /* Attribute const/noreturn are not reflected in mangling.  */
-  if (abi_version_at_least (5)
-      && (TREE_CODE (type) == FUNCTION_TYPE
-         || TREE_CODE (type) == METHOD_TYPE))
-    return 0;
-
   if (quals & TYPE_QUAL_RESTRICT)
     {
       write_char ('r');
index 7635092e6963754063b1c0567e62a27bfb3f0c6a..71fc429469c09ce3f35ba5218391ce04d61b8bb4 100644 (file)
@@ -1,3 +1,7 @@
+2011-03-07  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/abi/mangle46.C: New.
+
 2011-03-07  Pat Haugen <pthaugen@us.ibm.com>
 
        PR target/47862
diff --git a/gcc/testsuite/g++.dg/abi/mangle46.C b/gcc/testsuite/g++.dg/abi/mangle46.C
new file mode 100644 (file)
index 0000000..fddc88d
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/48008
+// { dg-options -fabi-version=5 }
+// Test that we retain function-cv-quals in template argument mangling.
+
+template <class T>
+struct A
+{ };
+
+typedef void cfn(int) const;
+typedef void fn(int);
+
+// { dg-final { scan-assembler  "_Z1f1AIFviEE" } }
+void f(A<fn>) { }
+// { dg-final { scan-assembler  "_Z1f1AIKFviEE" } }
+void f(A<cfn>) { }