Bug 54322 - [OOP] Wrong TARGET-attribute handling with CLASS IS/TYPE IS
Summary: [OOP] Wrong TARGET-attribute handling with CLASS IS/TYPE IS
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks:
 
Reported: 2012-08-19 15:33 UTC by Tobias Burnus
Modified: 2012-08-19 15:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-08-19 15:33:49 UTC
Reported at comp.lang.fortran, https://groups.google.com/forum/?fromgroups#!topic/comp.lang.fortran/11t7gAgUGD4 


The following piece of the program is invalid if PC_ALLOC is not a TARGET, however, gfortran accepts it:

   select type ( AN => pc_alloc )
      type is ( POINT_3D )
         p3d_poi=>AN


Note that this possibly not only affects pointer assignment but also passing as actual argument to an INTENT(IN) pointer dummy, and possibly other cases.


!------------- LONG TEST CASE ---------------

module mymod

type POINT
   real :: X, Y

   contains
      procedure :: s1 => sub1

end type POINT

type, extends(POINT) :: POINT_3D
   real :: Z
end type POINT_3D

type, extends(POINT) :: COLOR_POINT
   integer :: COLOR
end type COLOR_POINT


contains

subroutine sub1(this)
   class(POINT) :: this
end subroutine sub1

end module mymod


!================================================
program hello

   use mymod
   implicit none

   type(POINT), target :: P
   type(POINT_3D), target :: P3D
   type(COLOR_POINT), target :: CP
   class(POINT), pointer :: P_OR_CP

   class(POINT),allocatable::pc_alloc  !NO "TARGET"
   class(POINT_3D),pointer ::p3d_poi


   P_OR_CP=> CP
   allocate (POINT_3D :: pc_alloc)

   pc_alloc%X=1.
   pc_alloc%Y=2.

   select type ( AN => pc_alloc )
      class is ( POINT )
!      print *, AN%X, AN%Y

      type is ( POINT_3D )
         AN%Z=3.
         p3d_poi=>AN  ! INVALID if PC_ALLOC is not a TARGET
   end select

   print *, p3d_poi%X, p3d_poi%Y, p3d_poi%Z
end program