This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: gfortran accepting a target as pointer initialization espression
- From: marco restelli <mrestelli at gmail dot com>
- To: Janus Weil <janus at gcc dot gnu dot org>
- Cc: Fortran <fortran at gcc dot gnu dot org>
- Date: Thu, 5 Mar 2015 10:49:34 +0100
- Subject: Re: gfortran accepting a target as pointer initialization espression
- Authentication-results: sourceware.org; auth=none
- References: <CAHV2F1+_JpaaevZ9oKbnMn+YYagVbHdWjjwjq+YohHY3xnU_LQ at mail dot gmail dot com> <CAKwh3qgGAkzw+C+W5g1xX_N0ZJujg+j4cxRiPdjr2MmyQ1VWdA at mail dot gmail dot com> <CAHV2F1JLF02r1AR5B0c_wytYH6oAZPwAEKHcrx7QUbAOA5M5oA at mail dot gmail dot com>
- Reply-to: mrestelli at gmail dot com
2015-03-05 10:33 GMT+0100, marco restelli <mrestelli@gmail.com>:
> 2015-03-05 10:13 GMT+0100, Janus Weil <janus@gcc.gnu.org>:
>> Hi Marco,
>>
>> this kind of pointer initialization is an F08 feature, and I think
>> gfortran is right in accepting it according to the F08 standard.
>>
>> Note that it is being rejected when you ask for F03:
>>
>> $ gfortran -c test.f90 -std=f2003
>> test.f90:6.25:
>>
>> real, pointer :: pr => r
>> 1
>> Error: Fortran 2008: non-NULL pointer initialization at (1)
>
> Nice!
>
> (Sorry, I only tried with f2008 and did not think about changing that)
>
> Is this what is described by "null-init" and "initial-data-target", in
> R505 of the standard (section 5.2.1)?
>
> nitialization is = constant-expr
> or => null-init
> or => initial-data-target
>
> Then I have a follow-up question: gfortran refuses the following code
>
>
> module m1
> implicit none
>
> contains
> pure function f(x) result(y)
> real, intent(in) :: x
> real :: y
> y = 2.0*x
> end function f
> end module m1
>
>
> module m2
> use m1
> implicit none
>
> type :: t
> procedure(f), pointer, nopass :: p => null()
> end type t
>
> type(t) :: var_t = t(f)
> end module m2
>
>
>
> gfortran -std=f2008 -c pnt.f90 -o pnt.o
> pnt.f90:21:22:
>
> type(t) :: var_t = t(f)
> 1
> Error: Parameter »f« at (1) has not been declared or is a variable,
> which does not reduce to a constant expression
>
>
> Is this also valid f2008 or not?
Hi again,
another doubt along the same line. I see that the following code is
accepted (with f2008):
module m1
implicit none
contains
pure function f(x) result(y)
real, intent(in) :: x
real :: y
y = 2.0*x
end function f
end module m1
module m2
use m1
implicit none
procedure(f), pointer :: pf => f
end module m2
Isn't this a contradiction of
R506 null-init is function-reference
[...]
C512 (R506) The function-reference shall be a reference to the
intrinsic function NULL with no arguments.
Marco