]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/cp/decl.c
decl.c (pushdecl): Don't copy the type_decl.
[gcc.git] / gcc / cp / decl.c
index 804e2251b8dbdec3a83289822b91071e5054c1da..822874ecb458d4b093639733d100f3ad78f9368c 100644 (file)
@@ -3373,43 +3373,6 @@ pushdecl (x)
             {
              push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
 
-             if (!TREE_PERMANENT (x) 
-                 && TYPE_OBSTACK (type) != saveable_obstack)
-               {
-                 /* X should have been allocated on the saveable
-                    obstack.  Since the type was not, the type may
-                    outlive X, unless we make a copy of X.  Here are
-                    some examples:
-                    
-                    template <class T>
-                    void f()
-                    {
-                      typedef S<T> Type_t;
-                      Type_t::foo();
-                    }
-                    
-                    Here, we will create a SCOPE_REF with Type_t as
-                    its first argument, and save the SCOPE_REF for
-                    later, so that we can tsubst into it.  But, that
-                    means we need to save the TYPE_DECL for Type_t.
-                    
-                    But, we must save the TYPE_DECL even when not
-                    processing_template_decl.  For example,
-                    
-                    void f() 
-                    {
-                      typedef int I;
-                      g<I>();
-                    }
-                    
-                    may create a declaration of g with `I' as one of
-                    the arguments.  In the old days, we used to use
-                    the underlying types for things, but now we try
-                    to use the typedef names for readability.  */
-                 x = copy_node (x);
-                 copy_lang_decl (x);
-               }
-
              DECL_ORIGINAL_TYPE (x) = type;
               type = build_type_copy (type);
              TYPE_STUB_DECL (type) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
@@ -9624,7 +9587,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
       else if (current_lang_name == lang_name_java)
        decl = build_lang_decl (TYPE_DECL, declarator, type);
       else
-       decl = build_decl (TYPE_DECL, declarator, type);
+       {
+         /* Make sure this typedef lives as long as its type,
+            since it might be used as a template parameter. */
+         push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
+         decl = build_decl (TYPE_DECL, declarator, type);
+         pop_obstacks ();
+       }
 
       /* If the user declares "struct {...} foo" then `foo' will have
         an anonymous name.  Fill that name in now.  Nothing can
This page took 0.039293 seconds and 5 git commands to generate.