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: [EMAIL PROTECTED]> gfc --version GNU Fortran 95 (GCC 4.0.0 20050224 (experimental)) ... [EMAIL PROTECTED]> cat ~/packages/bugs/gfc_pointer_problem2.f90 [EMAIL PROTECTED]> gfc -static -o point gfc_pointer_problem2.f90 [EMAIL PROTECTED]> 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