This is a latent issue noticed when attempting a different approach to
fix PR122752.

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_template_id): Rebuild instead of modifying
        a TYPENAME_TYPE corresponding to a dependently-scoped template.
---
 gcc/cp/parser.cc | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 2160e16a099f..4ba9f6501edc 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -20426,10 +20426,15 @@ cp_parser_template_id (cp_parser *parser,
           && TREE_CODE (TREE_TYPE (templ)) == TYPENAME_TYPE)
     {
       /* Some type template in dependent scope.  */
-      tree &name = TYPENAME_TYPE_FULLNAME (TREE_TYPE (templ));
-      name = build_min_nt_loc (combined_loc,
-                              TEMPLATE_ID_EXPR,
-                              name, arguments);
+      tree fullname = TYPENAME_TYPE_FULLNAME (TREE_TYPE (templ));
+      fullname = build_min_nt_loc (combined_loc,
+                                  TEMPLATE_ID_EXPR,
+                                  fullname, arguments);
+      TREE_TYPE (templ)
+       = build_typename_type (TYPE_CONTEXT (TREE_TYPE (templ)),
+                              TYPE_NAME (TREE_TYPE (templ)),
+                              fullname,
+                              get_typename_type_tag (TREE_TYPE (templ)));
       template_id = templ;
     }
   else
-- 
2.52.0.209.ge85ae279b0

Reply via email to