[J3] ALLOCATE with source-expr determining the array bound & resulting lower bound
Tobias Burnus
burnus at net-b.de
Tue Nov 30 20:41:55 UTC 2021
Hello J3,
I have a question regarding the following which came up for GCC.
* NAG, Nvidia, flang yield a lower bounds of 'c' of 3 in the following example.
* ifort gives a lower bound of 1
* When fixing a related issue, GCC is about to change from 3 to 1
as collateral change.
However, my question is which value is the proper lower bound
of 'c' for:
implicit none
integer, allocatable :: c(:)
allocate(c, source=h(3))
write(*,*) lbound(c,1), ubound(c,1)
contains
pure function h(i) result(r)
integer, value, intent(in) :: i
integer, allocatable :: r(:)
allocate(r(3:5))
r = [1,2,3]
end function h
end
18-007r1 [134:27-29] has the following (and 21-007r2 [144:3-5] likewise):
"When an ALLOCATE statement is executed for an array with no
allocate-shape-spec-list, the bounds of source-expr determine
the bounds of the array."
Unless I missed something, the standard never quite says what the
bounds of an expression is. For the lower bound, I see it at two
places: In the LBOUND intrinsic itself – and at several places in
the standard, there is wording like the following (here for the
intrinsic assignment, 10.2.1.3, [161:17-18]):
"the shape of expr with each lower bound equal to the corresponding
element of LBOUND (expr) if expr is an array."
I do not see such wording for the ALLOCATE with the source-expr
and wonder whether it is missing.
Assuming the LBOUND rules apply, there is in 16.9.109 LBOUND [384:29-31]:
'ARRAY is a whole array, and ... Otherwise, if DIM is present, the result
value is 1.'
9.4.2 defines 'A whole array is a named array or a structure
component whose final part-ref is an array component name ...' [127:6-7]
And my reading is that h(3) returns an array but that one is not named;
thus, in my reading lbound(h(3),1) = 1. – And, using the LBOUND connection,
I infer lbound(c,1) = 1.
First question: Have I missed something?
Second question: Is some LBOUND wording needed for source-expr?
Tobias
More information about the J3
mailing list