c++: don't ICE on NAMESPACE_DECL inside FUNCTION_DECL
authorMatthias Kretz <m.kretz@gsi.de>
Wed, 15 Dec 2021 08:45:06 +0000 (09:45 +0100)
committerMatthias Kretz <m.kretz@gsi.de>
Sun, 19 Dec 2021 20:07:23 +0000 (21:07 +0100)
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 <m.kretz@gsi.de>
gcc/cp/ChangeLog:

* module.cc (trees_out::get_merge_kind): NAMESPACE_DECLs also
cannot have a DECL_TEMPLATE_INFO.

gcc/cp/module.cc

index f3e7af2..8451e3d 100644 (file)
@@ -10067,9 +10067,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));