From: Patrick Palka Date: Mon, 15 Dec 2025 20:03:43 +0000 (-0500) Subject: c++: avoid in-place modification of TYPENAME_TYPE X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=880492a8cb10d046b0162c31c9567c1e72d1be8f;p=thirdparty%2Fgcc.git c++: avoid in-place modification of TYPENAME_TYPE 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 --- diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 17199e013ba..394725fde39 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_tag (TREE_TYPE (templ))); template_id = templ; } else