This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC, Fortran, (pr66775)] Allocatable function result
- From: Mikael Morin <mikael dot morin at sfr dot fr>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: Andre Vehreschild <vehre at gmx dot de>, GCC-Patches-ML <gcc-patches at gcc dot gnu dot org>, GCC-Fortran-ML <fortran at gcc dot gnu dot org>, Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- Date: Sat, 11 Jul 2015 12:54:33 +0200
- Subject: Re: [RFC, Fortran, (pr66775)] Allocatable function result
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sfrmc.priv.atos.fr; dkim=none (no signature); dkim-adsp=none (no policy) header dot from=mikael dot morin at sfr dot fr
- References: <20150709122518 dot 08388506 at vepi2> <20150709175047 dot GA70209 at troutmask dot apl dot washington dot edu> <DE4F2D8C-D4E3-4CE3-8991-A0F372C555AA at gmx dot de> <20150709194131 dot GA29199 at troutmask dot apl dot washington dot edu> <20150710114432 dot 2adff6d8 at vepi2> <20150710134121 dot GA91910 at troutmask dot apl dot washington dot edu> <559FF0DF dot 8080107 at sfr dot fr> <20150710185713 dot GA92724 at troutmask dot apl dot washington dot edu>
Le 10/07/2015 20:57, Steve Kargl a écrit :
> On Fri, Jul 10, 2015 at 06:20:47PM +0200, Mikael Morin wrote:
>>
>> I'm not completely convinced by the standard excerpts that have been
>> quoted about this topic, as they don't have any explicit mention of
>> allocatable variables/expressions.
>
> I did not quote 12.3.3 about "characteristics of function results",
> which mentions the allocatable attribute. But, that is not
> necessarily relevant. The pieces I quoted explicitly states
>
> "On completion of execution of the function, the value returned
> is that of its function result. ... If the function result is
> not a pointer, its value shall be defined by the function."
Yeah, well, if the standard committee had allowed unallocated
allocatable results, they would have put it here together with pointer,
I guess.
>
> The function not only needs to allocate memory, it needs to
> assign it a value. In the following, if i <= 0, the function
> result is not defined.
>
> module foo
> contains
> function bar(i)
> integer, allocatable :: bar
> integer, intent(in) :: i
> if (i > 0) bar = i
> end function bar
> end module foo
>
> program test
> use foo
> integer j
> j = bar( 3); print *, j
> j = bar(-3); print *, j
> end if
> end program test
>
> Even if Andre developed a patch to allocate memory in
> bar() for the i <= 0 case to prevent the segfault, the
> function must return a value. What should that value be?
Your example is, of course, 100% invalid; a value is needed to put in j.
But the case is more debatable to me, if j is allocatable.
In that case an unallocated bar() result could just make j unallocated.
Mikael
- References:
- [RFC, Fortran, (pr66775)] Allocatable function result
- Re: [RFC, Fortran, (pr66775)] Allocatable function result
- Re: [RFC, Fortran, (pr66775)] Allocatable function result
- Re: [RFC, Fortran, (pr66775)] Allocatable function result
- Re: [RFC, Fortran, (pr66775)] Allocatable function result
- Re: [RFC, Fortran, (pr66775)] Allocatable function result
- Re: [RFC, Fortran, (pr66775)] Allocatable function result
- Re: [RFC, Fortran, (pr66775)] Allocatable function result