[C++ patch] Inline template methods

Jan Hubicka jh@suse.cz
Sun Feb 1 10:01:00 GMT 2004


Hi,
while looking at the "export" keyword thread, I noticed that we never
inline template methods when they are not explicitely makred "inline".
This is because they always are weak and we are affraid to inline
something that may not be bound locally.
While this rule I think can make sense for C where if I weakize
something, i am doing so because I want to overwrite it by something
different, I think the implementation of COMDAT flag in C++ is not this
category.

This patch is about the most conservative approach I can come with.
Does it look OK?  I would prefer something like this to go to 3.4 too.

Honza

2004-02-01  Jan Hubicka  <jh@suse.cz>
	* tree.c (cp_cannot_inline_tree_fn): Allow inlining of COMDAT
	functions.
Index: cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.361
diff -c -3 -p -r1.361 tree.c
*** cp/tree.c	30 Jan 2004 23:37:39 -0000	1.361
--- cp/tree.c	1 Feb 2004 00:56:08 -0000
*************** cp_cannot_inline_tree_fn (tree* fnp)
*** 2062,2069 ****
      return 1;
  
    /* Don't auto-inline anything that might not be bound within
!      this unit of translation.  */
!   if (!DECL_DECLARED_INLINE_P (fn) && !(*targetm.binds_local_p) (fn))
      {
        DECL_UNINLINABLE (fn) = 1;
        return 1;
--- 2062,2073 ----
      return 1;
  
    /* Don't auto-inline anything that might not be bound within
!      this unit of translation.
!      Exclude comdat functions from this rule.  While they can be bound
!      to the other unit, they all must be the same.  This is especilly
!      important so templates can inline.  */
!   if (!DECL_DECLARED_INLINE_P (fn) && !(*targetm.binds_local_p) (fn)
!       && !DECL_COMDAT (fn))
      {
        DECL_UNINLINABLE (fn) = 1;
        return 1;



More information about the Gcc-patches mailing list