[Bug fortran/20520] allocatable arrays used uninitialized without a warning
burnus at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Jun 25 20:50:00 GMT 2007
------- Comment #9 from burnus at gcc dot gnu dot org 2007-06-25 20:49 -------
Besides local allocated variables, one can think of local pointers as well:
integer, pointer :: a
a = 4 ! wrong
if(associated(a)) ! wrong
nullify(a)
if(associated(a)) ! ok
a = 4 ! wrong
For allocation, one could also think about:
subroutine foo(a)
integer, intent(out), allocatable :: a(:)
a = 5 ! wrong: error!
---------
interface
subroutine bar1(x); integer, intent(in), allocatable :: x(:); end subroutine
subroutine bar2(x); integer :: x(:); end subroutine
end interface
integer, allocatable :: a(:)
! call bar1(a) ! ok as if(allocated(a)) is used -> no warning
! -- or --
call bar2(a) ! invalid though harmless as long bar2 does not use the variable
! -> warning
Analogously, for pointer, except that one could check for NULL as well:
interface
subroutine bar1(x); integer, intent(in), pointer :: x(:); end subroutine
subroutine bar2(x); integer :: x(:); end subroutine
end interface
integer, allocatable :: a(:)
call bar1(a) ! potentially invalid (unless bar1 does not use the variable)
! as the pointer has unknown status -> warning
call bar2(a) ! wrong (harmless if not accessed) -> warning
nullify(a)
call bar2(a) ! -> invalid (unless bar2 does not use the variable) -> warning
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20520
More information about the Gcc-bugs
mailing list