This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/20406] New: SIZE() matters?
- From: "dave dot offiler at metoffice dot gov dot uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Mar 2005 14:54:15 -0000
- Subject: [Bug fortran/20406] New: SIZE() matters?
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Dear gfortran developers,
This is not a bug, but perhaps in the class of 'unexpected, but notincorrect,
behaviour'. This is just for your attention, but not (necessarily) for action as
I'm sure there are vastly more important things to deal with.
The issue is the return value from size() when the argument is an unassigned
pointer - gfortran returns 1. This is illustrated in the attached code snippet.
We feel that logically, size() should return zero in these cases (as the Intel
and NAG compilers do) or a negative value. However, we accept that any
arbitrary value could be returned - as the result is probably undefined
according the standards. Not that it should be relied upon, or in a good
program, even allowed to occur!
The reason for not doing an allocate() and then doing the test with size() and
not associated() before deallocation has some history and a complex logic that I
won't bore you with here. Suffice to say we are now doing the test properly...
All the best,
Dave
On RH9 Linux:
frdo@eld091> gfc --version
GNU Fortran 95 (GCC 4.0.0 20050224 (experimental))
...
frdo@eld091> cat ~/packages/bugs/gfc_pointer_problem2.f90
!!!frdo@eld091> gfc -static -o point gfc_pointer_problem2.f90
!!!frdo@eld091> point
!!! x associated? F
!!! size of x? 1
!!!Fortran runtime error: Internal: Attempt to DEALLOCATE unallocated memory.
!!!
program point
integer, pointer :: x(:) => null()
print *, 'x associated?', associated(x)
print *, 'size of x? ', size(x) !!! gfc says 1, ifc=nag=0
if(size(x)>0)deallocate(x) !!! wrong!
!!! if (associated(x)) deallocate(x) !!! correct
end program point
--
Summary: SIZE() matters?
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dave dot offiler at metoffice dot gov dot uk
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20406