This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, Fortran] PR 47266: Mark privat module procedures as TREE_PUBLIC=0
- From: Ian Harvey <ian_harvey at bigpond dot com>
- To: fortran at gcc dot gnu dot org
- Date: Sat, 15 Jan 2011 14:37:08 +1100
- Subject: Re: [Patch, Fortran] PR 47266: Mark privat module procedures as TREE_PUBLIC=0
- References: <4D2F671F.6070403@net-b.de>
- Reply-to: ian_harvey at bigpond dot com
On 14/01/2011 7:57 AM, Tobias Burnus wrote:
Module procedures which are marked as PRIVATE do not need to be
available outside of the translation unit - thus they do not need to be
TREE_PUBLIC (unless they are bind(C)).
Private functions that are used in specification expressions for the
length of a function result for public functions may need further
consideration. For example:
! In mod-with_priv_fun.f90
MODULE mod_with_priv_fun
IMPLICIT NONE
PRIVATE
PUBLIC :: pub_fun
PRIVATE :: priv_fun
CONTAINS
FUNCTION pub_fun(arg) RESULT(s)
INTEGER, INTENT(IN) :: arg
CHARACTER(LEN=priv_fun(arg)) :: s
!****
s = 'ABCDEFGHHIJKLMNOPQRSTUVWXYZ'
END FUNCTION pub_fun
PURE FUNCTION priv_fun(arg) RESULT(l)
INTEGER, INTENT(IN) :: arg
INTEGER :: l
!****
l = arg + 1
END FUNCTION priv_fun
END MODULE mod_with_priv_fun
! In test_driver.f90
PROGRAM test_driver
USE mod_with_priv_fun
IMPLICIT NONE
CHARACTER(20) :: s
s = pub_fun(4) // '--'
PRINT "(A)", s
END PROGRAM test_driver
fails with a link error (undefined symbol
__mod_with_priv_fun_MOD_priv_fun) with this patch.
(Note the attribute needs to be explicitly set on the private function
to see the link problem.)
PR44265 demonstrates a similar problem (but for parameters) where
otherwise "private" symbols need to be visible in the outside world.