[Bug fortran/86151] New: size() of unallocated array is nonzero
rbramley at letterboxes dot org
gcc-bugzilla@gcc.gnu.org
Thu Jun 14 12:44:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86151
Bug ID: 86151
Summary: size() of unallocated array is nonzero
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: rbramley at letterboxes dot org
Target Milestone: ---
Created attachment 44274
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44274&action=edit
version of code sizetest.f90
In the following program, gfortran 8.0.1 shows the size of an unallocated array
as being 1 in both dimensions, but a correct shape of [0 0]:
program sizetest
use iso_fortran_env, only: real8 => real64, stdout => output_unit
implicit none
integer, parameter:: n = 3, m = 4
real(real8), allocatable :: x(:,:)
real(real8), allocatable :: z(:,:)
allocate(x(m,n))
write(stdout,*) '==================================='
write(stdout,*) 'Allocated 2D array x: '
write(stdout,*) 'shape(x) = ', shape(x)
write(stdout,*) 'size(x) = ', size(x)
write(stdout,*) 'size(x,1) = ', size(x,1)
write(stdout,*) 'size(x,2) = ', size(x,2)
write(stdout,*) '==================================='
write(stdout,*) 'Unallocated 2D array z: '
write(stdout,*) 'shape(z) = ', shape(z)
write(stdout,*) 'size(z) = ', size(z)
write(stdout,*) 'size(z,1) = ', size(z,1)
write(stdout,*) 'size(z,2) = ', size(z,2)
end program sizetest
(I've also put the code as an attachment in case it's easier for you to extract
that way, versus using cut and paste.)
The output using gfortran with default options is:
===================================
Allocated 2D array x:
shape(x) = 4 3
size(x) = 12
size(x,1) = 4
size(x,2) = 3
===================================
Unallocated 2D array z:
shape(z) = 0 0
size(z) = 1
size(z,1) = 1
size(z,2) = 1
For the array x, all is as expected. For z, however, I expected all three
size() inquiries to yield 0. Intel fortran returns zeros for those. It's not
clear to me if the size of an unallocated array is specified by the Fortran
standard, or is in the category of "just don't do that".
Irrelevant addendum: I really appreciate the years of hard work and effort the
gfortran team has put into the project. And the patience you've show for fools
and noobs with dumb questions, a category this report may end up falling into.
In any case, thank you for creating a tool of great use to many people.
More information about the Gcc-bugs
mailing list