]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/7754 (ICE SIGSEGV on union with template parameter)
authorMark Mitchell <mark@codesourcery.com>
Tue, 8 Oct 2002 22:53:21 +0000 (22:53 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 8 Oct 2002 22:53:21 +0000 (22:53 +0000)
PR c++/7754
* decl2.c (finish_anon_union): Do not expand anonymous unions when
procesing template functions.
* pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
type. Call layout_decl.
(tsubst_expr, case DECL_STMT): Handle anonymous unions.

From-SVN: r57962

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/pt.c

index f4738ece154dfb28faf18e4a427dd3fa5168aa9f..3ad9c7141e06d9ec21c3a29328068fd7ff2244d0 100644 (file)
@@ -1,3 +1,12 @@
+2002-10-03  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/7754
+       * decl2.c (finish_anon_union): Do not expand anonymous unions when
+       procesing template functions.
+       * pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
+       type. Call layout_decl.
+       (tsubst_expr, case DECL_STMT): Handle anonymous unions.
+
 2002-10-07  Richard Henderson  <rth@redhat.com>
 
        * decl2.c: Complete reversion of c++/7754.
index 0eb47994b20ab07afefe1283ebf588e7fb569377..43349631b4de6c6431903f1372b6f12b04a87980 100644 (file)
@@ -1975,26 +1975,31 @@ finish_anon_union (anon_union_decl)
       return;
     }
 
-  main_decl = build_anon_union_vars (anon_union_decl,
-                                    &DECL_ANON_UNION_ELEMS (anon_union_decl),
-                                    static_p, external_p);
-
-  if (main_decl == NULL_TREE)
+  if (!processing_template_decl)
     {
-      warning ("anonymous aggregate with no members");
-      return;
-    }
+      main_decl 
+       = build_anon_union_vars (anon_union_decl,
+                                &DECL_ANON_UNION_ELEMS (anon_union_decl),
+                                static_p, external_p);
+      
+      if (main_decl == NULL_TREE)
+       {
+         warning ("anonymous aggregate with no members");
+         return;
+       }
 
-  if (static_p)
-    {
-      make_decl_rtl (main_decl, 0);
-      COPY_DECL_RTL (main_decl, anon_union_decl);
-      expand_anon_union_decl (anon_union_decl, 
-                             NULL_TREE,
-                             DECL_ANON_UNION_ELEMS (anon_union_decl));
+      if (static_p)
+       {
+         make_decl_rtl (main_decl, 0);
+         COPY_DECL_RTL (main_decl, anon_union_decl);
+         expand_anon_union_decl (anon_union_decl, 
+                                 NULL_TREE,
+                                 DECL_ANON_UNION_ELEMS (anon_union_decl));
+         return;
+       }
     }
-  else
-    add_decl_stmt (anon_union_decl);
+
+  add_decl_stmt (anon_union_decl);
 }
 
 /* Finish processing a builtin type TYPE.  It's name is NAME,
index 69789d5d33d9a4bbc1eff27134d0e8b605bba090..8fc9f743e1e033bc41d03b2da24900bf36a106cb 100644 (file)
@@ -6079,6 +6079,8 @@ tsubst_decl (t, args, type, complain)
          }
 
        r = copy_decl (t);
+       if (TREE_CODE (r) == VAR_DECL)
+         type = complete_type (type);
        TREE_TYPE (r) = type;
        c_apply_type_quals_to_decl (cp_type_quals (type), r);
        DECL_CONTEXT (r) = ctx;
@@ -6115,6 +6117,8 @@ tsubst_decl (t, args, type, complain)
        TREE_CHAIN (r) = NULL_TREE;
        if (TREE_CODE (r) == VAR_DECL && VOID_TYPE_P (type))
          cp_error_at ("instantiation of `%D' as type `%T'", r, type);
+       /* Compute the size, alignment, etc. of R.  */
+       layout_decl (r, 0);
       }
       break;
 
@@ -7374,9 +7378,6 @@ tsubst_expr (t, args, complain, in_decl)
            decl = tsubst (decl, args, complain, in_decl);
            if (decl != error_mark_node)
              {
-                if (TREE_CODE (decl) != TYPE_DECL)
-                  /* Make sure the type is instantiated now. */
-                  complete_type (TREE_TYPE (decl));
                if (init)
                  DECL_INITIAL (decl) = error_mark_node;
                /* By marking the declaration as instantiated, we avoid
@@ -7386,19 +7387,26 @@ tsubst_expr (t, args, complain, in_decl)
                   do.  */
                if (TREE_CODE (decl) == VAR_DECL)
                  DECL_TEMPLATE_INSTANTIATED (decl) = 1;
-               maybe_push_decl (decl);
-               if (DECL_PRETTY_FUNCTION_P (decl))
+               if (TREE_CODE (decl) == VAR_DECL
+                   && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
+                 /* Anonymous aggregates are a special case.  */
+                 finish_anon_union (decl);
+               else 
                  {
-                   /* For __PRETTY_FUNCTION__ we have to adjust the
-                      initializer.  */
-                   const char *const name
-                     = (*decl_printable_name) (current_function_decl, 2);
-                   init = cp_fname_init (name);
-                   TREE_TYPE (decl) = TREE_TYPE (init);
+                   maybe_push_decl (decl);
+                   if (DECL_PRETTY_FUNCTION_P (decl))
+                     {
+                       /* For __PRETTY_FUNCTION__ we have to adjust the
+                          initializer.  */
+                       const char *const name
+                         = (*decl_printable_name) (current_function_decl, 2);
+                       init = cp_fname_init (name);
+                       TREE_TYPE (decl) = TREE_TYPE (init);
+                     }
+                   else
+                     init = tsubst_expr (init, args, complain, in_decl);
+                   cp_finish_decl (decl, init, NULL_TREE, 0);
                  }
-               else
-                 init = tsubst_expr (init, args, complain, in_decl);
-               cp_finish_decl (decl, init, NULL_TREE, 0);
              }
          }