This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/20520] allocatable arrays used uninitialized without a warning
- From: "burnus at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Jun 2007 20:49:52 -0000
- Subject: [Bug fortran/20520] allocatable arrays used uninitialized without a warning
- References: <bug-20520-10294@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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