From 1eee4e08a64f6e931b0c5dd1bb854a2b7ad3d58f Mon Sep 17 00:00:00 2001 From: Matthias Kretz Date: Wed, 15 Dec 2021 09:45:06 +0100 Subject: [PATCH] c++: don't ICE on NAMESPACE_DECL inside FUNCTION_DECL Code like void swap() { namespace __variant = __detail::__variant; ... } create a NAMESPACE_DECL where the CP_DECL_CONTEXT is a FUNCTION_DECL. DECL_TEMPLATE_INFO fails on NAMESPACE_DECL and therefore must be handled first in the assertion. Signed-off-by: Matthias Kretz gcc/cp/ChangeLog: * module.cc (trees_out::get_merge_kind): NAMESPACE_DECLs also cannot have a DECL_TEMPLATE_INFO. (cherry picked from commit 6bcb6ed5a44b6f271891246ef7ae568bfdc14e9c) --- gcc/cp/module.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index b97b1bcb2f8b..6cb926c044a2 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -10059,9 +10059,10 @@ trees_out::get_merge_kind (tree decl, depset *dep) tree ctx = CP_DECL_CONTEXT (decl); if (TREE_CODE (ctx) == FUNCTION_DECL) { - /* USING_DECLs cannot have DECL_TEMPLATE_INFO -- this isn't - permitting them to have one. */ + /* USING_DECLs and NAMESPACE_DECLs cannot have DECL_TEMPLATE_INFO -- + this isn't permitting them to have one. */ gcc_checking_assert (TREE_CODE (decl) == USING_DECL + || TREE_CODE (decl) == NAMESPACE_DECL || !DECL_LANG_SPECIFIC (decl) || !DECL_TEMPLATE_INFO (decl)); -- 2.43.5