public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly
@ 2011-08-29 13:46 arjen.markus895 at gmail dot com
  2011-08-29 14:01 ` [Bug fortran/50225] " dominiq at lps dot ens.fr
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: arjen.markus895 at gmail dot com @ 2011-08-29 13:46 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50225
           Summary: The allocation status for polymorphic allocatable
                    variables is not set properly
    Classification: Unclassified
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: arjen.markus895@gmail.com


If you compile the program below with "-fcheck=all", it fails, claiming that 
the result variable in the function add_vector() is already allocated. The 
error disappears when you change "class(point2d)" to "type(point2d)".

(In a more elaborate version of the program, it also fails without this option
and with this option there is a segmentation fault.)

module points2d3d

  implicit none

  type point2d
      real :: x, y

  end type

contains

 subroutine print( point )

   class(point2d) :: point
   write(*,'(2f10.4)') point%x, point%y
 end subroutine


 subroutine random_vector( point )

   class(point2d) :: point
   call random_number( point%x )
   call random_number( point%y )
   point%x = 2.0 * (point%x - 0.5)
   point%y = 2.0 * (point%y - 0.5)
 end subroutine


 function add_vector( point, vector )

   class(point2d), intent(in)  :: point, vector
   class(point2d), allocatable :: add_vector

   allocate( add_vector )
   add_vector%x = point%x + vector%x
   add_vector%y = point%y + vector%y
 end function


end module points2d3d


program random_walk

 use points2d3d


 type(point2d), target   :: point_2d, vector_2d
 class(point2d), pointer :: point, vector
 integer :: i


 point  => point_2d
 vector => vector_2d
 write(*,*) 'Two-dimensional walk:'


 do i=1,10
   call random_vector(point)
   call random_vector(vector)
   call print(add_vector(point, vector))
 end do

end program random_walk


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-08-29 21:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-29 13:46 [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly arjen.markus895 at gmail dot com
2011-08-29 14:01 ` [Bug fortran/50225] " dominiq at lps dot ens.fr
2011-08-29 14:28 ` [Bug fortran/50225] [OOP] " burnus at gcc dot gnu.org
2011-08-29 17:08 ` janus at gcc dot gnu.org
2011-08-30  0:23 ` [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable function results " janus at gcc dot gnu.org
2011-08-30  1:12 ` janus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).