pt.c (pop_tinst_level): Call extract_interface_info.
authorJason Merrill <jason@yorick.cygnus.com>
Sun, 4 Oct 1998 20:10:49 +0000 (20:10 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 4 Oct 1998 20:10:49 +0000 (16:10 -0400)
* pt.c (pop_tinst_level): Call extract_interface_info.
(instantiate_decl): Don't save and restore file position.
* decl.c (cp_finish_decl): Make statics in extern inlines and
templates common, if possible and the target doesn't support weak
symbols.

From-SVN: r22824

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/pt.c

index bd2880276775aa6ba6b601e7d3ac4cc4803211e9..d803d39328e20351cce85fe3be1e264ce33cf312 100644 (file)
@@ -1,5 +1,12 @@
 1998-10-04  Jason Merrill  <jason@yorick.cygnus.com>
 
+       * pt.c (pop_tinst_level): Call extract_interface_info.
+       (instantiate_decl): Don't save and restore file position.
+
+       * decl.c (cp_finish_decl): Make statics in extern inlines and
+       templates common, if possible and the target doesn't support weak
+       symbols.
+
        * decl.c (grokdeclarator): Remove redundant calls to
        build_type_variant and some duplicated code.
        * sig.c (build_signature_reference_type): Only take the type parm.
index 9c4e08aaa633e4a4ceffeed80d234087b3c1ce56..cae72561e0cafcd3a56305415f168d3176351c0e 100644 (file)
@@ -7298,20 +7298,52 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
       if (was_temp)
        end_temporary_allocation ();
 
-      /* Extern inline function static data has external linkage.
-         Instead of trying to deal with that, we disable inlining of
-         such functions.  The ASM_WRITTEN check is to avoid hitting this
-         for __FUNCTION__.  */
+      /* Static data in a function with comdat linkage also has comdat
+         linkage.  */
       if (TREE_CODE (decl) == VAR_DECL
          && TREE_STATIC (decl)
+         /* Don't mess with __FUNCTION__.  */
          && ! TREE_ASM_WRITTEN (decl)
          && current_function_decl
          && DECL_CONTEXT (decl) == current_function_decl
-         && DECL_THIS_INLINE (current_function_decl)
+         && (DECL_THIS_INLINE (current_function_decl)
+             || DECL_TEMPLATE_INSTANTIATION (current_function_decl))
          && TREE_PUBLIC (current_function_decl))
        {
+         /* Rather than try to get this right with inlining, we suppress
+            inlining of such functions.  */
          current_function_cannot_inline
            = "function with static variable cannot be inline";
+
+         /* If flag_weak, we don't need to mess with this, as we can just
+            make the function weak, and let it refer to its unique local
+            copy.  This works because we don't allow the function to be
+            inlined.  */
+         if (! flag_weak)
+           {
+             if (DECL_INTERFACE_KNOWN (current_function_decl))
+               {
+                 TREE_PUBLIC (decl) = 1;
+                 DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl);
+               }
+             else if (DECL_INITIAL (decl) == NULL_TREE
+                      || DECL_INITIAL (decl) == error_mark_node)
+               {
+                 TREE_PUBLIC (decl) = 1;
+                 DECL_COMMON (decl) = 1;
+               }
+             /* else we lose. We can only do this if we can use common,
+                 which we can't if it has been initialized.  */
+
+             if (TREE_PUBLIC (decl))
+               DECL_ASSEMBLER_NAME (decl)
+                 = build_static_name (current_function_decl, DECL_NAME (decl));
+             else if (! DECL_ARTIFICIAL (decl))
+               {
+                 cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
+                 cp_warning_at ("  you can work around this by removing the initializer"), decl;
+               }
+           }
        }
 
       else if (TREE_CODE (decl) == VAR_DECL
index e08eaff3e8cb1bc515d03081814d23053164f078..1545c069f491b5b283b842fe154c3b07a4eea8d1 100644 (file)
@@ -3995,6 +3995,7 @@ pop_tinst_level ()
      this instantiation.  */
   lineno = old->line;
   input_filename = old->file;
+  extract_interface_info ();
   
   current_tinst_level = old->next;
   old->next = free_tinst_level;
@@ -8004,8 +8005,6 @@ instantiate_decl (d)
   tree gen_tmpl;
   int nested = in_function_p ();
   int pattern_defined;
-  int line = lineno;
-  char *file = input_filename;
 
   /* This function should only be used to instantiate templates for
      functions and static member variables.  */
@@ -8142,9 +8141,6 @@ instantiate_decl (d)
     {
       /* Defer all templates except inline functions used in another
          function.  */
-      lineno = line;
-      input_filename = file;
-
       if (at_eof && !pattern_defined 
          && DECL_EXPLICIT_INSTANTIATION (d))
        /* [temp.explicit]
@@ -8217,9 +8213,6 @@ instantiate_decl (d)
     }
 
 out:
-  lineno = line;
-  input_filename = file;
-
   pop_from_top_level ();
   pop_tinst_level ();