]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: avoid in-place modification of TYPENAME_TYPE
authorPatrick Palka <ppalka@redhat.com>
Mon, 15 Dec 2025 20:03:43 +0000 (15:03 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 15 Dec 2025 20:03:43 +0000 (15:03 -0500)
Since we have a TYPENAME_TYPE cache, through which equivalent
TYPENAME_TYPEs are reused, in-place modification of a TYPENAME_TYPE is
generally unsafe.  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.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/parser.cc

index 17199e013ba17f9c792f3f3e3c7a3adf75f47ff1..394725fde394d1d3599c15ff5b573285ee62ba2a 100644 (file)
@@ -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_tag (TREE_TYPE (templ)));
       template_id = templ;
     }
   else