[J3] Is this code valid?
Robert Corbett
rpcorbett at att.net
Wed Apr 30 02:38:43 UTC 2025
The Fortran 2023 standard as written is clearin this case. The reference to the variable"this" in the BLOCK construct is not standardconforming. The refer to the variable "this"in the subroutine is standard conforming.
In the following text, all references are toJ3/24-007.
The dummy argument "this" declared in thesubroutine "init" is a named variable.Therefore, that "this" is a local identifier(see 19.3.1, p1). The scope of a localidentifier is an inclusive scope (see 19.1, p2).The inclusive scope of the variable "this"declared in the subroutine "init" includesthe scope of the BLOCK construct (see 3.83).The occurrence of "this" in the BLOCK construct is not host associated with the variable "this"in the subroutine "init". It is an in scopereference to the variable "this" declared inthe subroutine "init". Therefore, item (4) inparagraph 1 of 10.1.11 does not apply to theoccurrence of "this" in the BLOCK construct.
The occurrence of "this" in the internalsubroutine is host associated with the namedvariable "this" declared in the subroutine"init", and so item (4) of the list inparagraph 1 of 10.1.11 does apply in thiscase.
I suspect that the restriction was not anintentional restriction. I think it wasthe result of an oversight when the BLOCK construct was added to the language. Inot a member of the committee when the BLOCKconstruct was added to the language, so Ihave no direct knowledge.
I do not see that allowing the appearance of"this" in the BLOCK construct violates anyconstraint. Because there are conflictingimplementations, I recommend against issuingan erratum to Fortran 2023. The committeecan address the issue in the next edition ofthe standard.
Robert Corbett
On Tuesday, April 29, 2025 at 07:36:22 AM PDT, Carlson, Neil via J3 <j3 at mailman.j3-fortran.org> wrote:
#yiv1349336275 P {margin-top:0;margin-bottom:0;}In the following example, a subroutine declares two arrays, one within a BLOCK and the other within an internal subroutine. The specification expressions involve a designator whose base object is a dummy argument in the host subroutine with INTENT(OUT).
The NAG compiler accepts both as valid, while Intel and gfortran reject both citing 10.11.1 item 2 (essentially). However item 4 would seem to apply (making this valid) since the base object is made accessible by host association. This seems pretty clear to me in the case of the internal subroutine, though much less so in the BLOCK case. What do you think?
-Neil
module foo
type :: bar integer :: n end type
contains
subroutine init(this, n) type(bar), intent(out) :: this integer, intent(in) :: n this%n = n block real :: array1(this%n) end block call sub contains subroutine sub real :: array2(this%n) end subroutine end subroutine
end module
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20250430/4c123391/attachment-0001.htm>
More information about the J3
mailing list