In some cases, when doing a pointer assignment with a arrays, the upper and
lower bounds on the pointer are not the same as on the pointee. This happens in
the convoluted case of a pointer declared in a module that is assigned to in a
subroutine. In the caller of that subroutine, the bounds of that pointer are
coming out incorrect. Below is a sample code showing the problem. It can be
built without any compiler options. I get this with the most recent version of
gfortran on linux (FC5).
$ gfortran --version
GNU Fortran (GCC) 4.3.0 20070821 (experimental) [trunk revision 127658]

Here is the sample program
-----------------------
module Lattice
integer:: ndrft
real(kind=8),pointer:: drftzs(:)
end module Lattice
program badpointerdims
use Lattice
real(kind=8),pointer:: p(:)
ndrft = 100
allocate(p(0:100))
call topsetpointerdrftzs(p)
print*,"p bounds ",lbound(p),ubound(p)
print*,"drftzs bounds ",lbound(drftzs),ubound(drftzs)
stop
end badpointerdims
subroutine setpointerdrftzs(p)
use Lattice
real(kind=8),target::p(0:ndrft)
drftzs => p
return
end setpointerdrftzs
-----------------------

The program prints the following output
 p bounds            0         100
 d bounds            1         101
I would expect that the d bounds be the same as the p bounds.

Thanks for your help!
   Dave


-- 
           Summary: array pointer assignment gives incorrect dimensions
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dpgrote at lbl dot gov


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33139

Reply via email to