From: Jason Merrill Date: Fri, 2 Apr 2021 09:45:02 +0000 (-0400) Subject: c++: Fix print-tree for TEMPLATE_DECL X-Git-Tag: basepoints/gcc-12~273 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a44a753a35542f86e82e198595ce3553f6d718f6;p=thirdparty%2Fgcc.git c++: Fix print-tree for TEMPLATE_DECL The if allows TEMPLATE_DECL, but then checking DECL_MODULE_IMPORT_P crashes on TEMPLATE_DECL. Fixed by stripping TEMPLATE_DECL first. gcc/cp/ChangeLog: * ptree.c (cxx_print_decl): Check DECL_MODULE_IMPORT_P on template result. --- diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c index 95a4fdf284ae..33b73fb24b61 100644 --- a/gcc/cp/ptree.c +++ b/gcc/cp/ptree.c @@ -59,16 +59,16 @@ cxx_print_decl (FILE *file, tree node, int indent) bool need_indent = true; - if (TREE_CODE (node) == FUNCTION_DECL - || TREE_CODE (node) == VAR_DECL - || TREE_CODE (node) == TYPE_DECL - || TREE_CODE (node) == TEMPLATE_DECL - || TREE_CODE (node) == CONCEPT_DECL - || TREE_CODE (node) == NAMESPACE_DECL) + tree ntnode = STRIP_TEMPLATE (node); + if (TREE_CODE (ntnode) == FUNCTION_DECL + || TREE_CODE (ntnode) == VAR_DECL + || TREE_CODE (ntnode) == TYPE_DECL + || TREE_CODE (ntnode) == CONCEPT_DECL + || TREE_CODE (ntnode) == NAMESPACE_DECL) { unsigned m = 0; - if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_IMPORT_P (node)) - m = get_importing_module (node, true); + if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_IMPORT_P (ntnode)) + m = get_importing_module (ntnode, true); if (const char *name = m == ~0u ? "" : module_name (m, true)) { @@ -78,7 +78,7 @@ cxx_print_decl (FILE *file, tree node, int indent) need_indent = false; } - if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_PURVIEW_P (node)) + if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_PURVIEW_P (ntnode)) { if (need_indent) indent_to (file, indent + 3);