+/* Helper for replace_typedefs_qualified_name to handle
+ DEMANGLE_COMPONENT_TEMPLATE. TMPL is the template node. BUF is
+ the buffer that holds the qualified name being built by
+ replace_typedefs_qualified_name. REPL is the node that will be
+ rewritten as a DEMANGLE_COMPONENT_NAME node holding the 'template
+ plus template arguments' name with typedefs replaced. */
+
+static bool
+replace_typedefs_template (struct demangle_parse_info *info,
+ string_file &buf,
+ struct demangle_component *tmpl,
+ struct demangle_component *repl,
+ canonicalization_ftype *finder,
+ void *data)
+{
+ demangle_component *tmpl_arglist = d_right (tmpl);
+
+ /* Replace typedefs in the template argument list. */
+ replace_typedefs (info, tmpl_arglist, finder, data);
+
+ /* Convert 'template + replaced template argument list' to a string
+ and replace the REPL node. */
+ gdb::unique_xmalloc_ptr<char> tmpl_str = cp_comp_to_string (tmpl, 100);
+ if (tmpl_str == nullptr)
+ {
+ /* If something went astray, abort typedef substitutions. */
+ return false;
+ }
+ buf.puts (tmpl_str.get ());
+
+ repl->type = DEMANGLE_COMPONENT_NAME;
+ repl->u.s_name.s = obstack_strdup (&info->obstack, buf.string ());
+ repl->u.s_name.len = buf.size ();
+ return true;
+}
+