https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109443

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Making the reference types to return or parameter non-POD types passed by value
restrict could be
--- gcc/cp/call.cc.jj   2023-03-30 09:34:05.609725768 +0200
+++ gcc/cp/call.cc      2023-04-13 09:56:53.226908996 +0200
@@ -9223,7 +9223,11 @@ type_passed_as (tree type)
 {
   /* Pass classes with copy ctors by invisible reference.  */
   if (TREE_ADDRESSABLE (type))
-    type = build_reference_type (type);
+    {
+      type = build_reference_type (type);
+      type = build_qualified_type (type,
+                                  TYPE_QUALS (type) | TYPE_QUAL_RESTRICT);
+    }
   else if (targetm.calls.promote_prototypes (NULL_TREE)
           && INTEGRAL_TYPE_P (type)
           && COMPLETE_TYPE_P (type)
--- gcc/cp/cp-gimplify.cc.jj    2023-03-15 15:36:02.500430556 +0100
+++ gcc/cp/cp-gimplify.cc       2023-04-13 09:57:51.989059798 +0200
@@ -2000,6 +2000,9 @@ cp_genericize (tree fndecl)
     {
       t = DECL_RESULT (fndecl);
       TREE_TYPE (t) = build_reference_type (TREE_TYPE (t));
+      TREE_TYPE (t)
+       = build_qualified_type (TREE_TYPE (t), TYPE_QUALS (TREE_TYPE (t))
+                                              | TYPE_QUAL_RESTRICT);
       DECL_BY_REFERENCE (t) = 1;
       TREE_ADDRESSABLE (t) = 0;
       relayout_decl (t);

Completely untested.  Does this what we want?  Stage1 material anyway...

Reply via email to