---
 gcc/cp/pt.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dea1ec0..6e209f8 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -21317,8 +21317,15 @@ add_implicit_template_parms (size_t count, tree 
parameters)
 
       // Rewrite the type of P to be the template_parm added above (getdecls is
       // used to retrieve it since it is the most recent declaration in this
-      // scope).
-      TREE_TYPE (generic_type_ptr) = TREE_TYPE (getdecls ());
+      // scope).  Qualifiers need to be preserved also.
+
+      tree& cur_type = TREE_TYPE (generic_type_ptr);
+      tree new_type = TREE_TYPE (getdecls ());
+
+      if (TYPE_QUALS (cur_type))
+       cur_type = cp_build_qualified_type (new_type, TYPE_QUALS (cur_type));
+      else
+       cur_type = new_type;
     }
 
   gcc_assert (synth_idx == count);
-- 
1.8.3

Reply via email to