This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran, OOP] PR 43207: [OOP] invalid (pointer) assignment to and from abstract non-polymorphic expressions


Hi all,

the attached patch fixes the PR in the subject line by introducing a
new check to reject invalid code. It's a slight update of an old patch
that I posted in the PR quite some time ago, using somewhat tighter
checking to avoid side effects on the testsuite.

Regtests cleanly on x86_64-linux-gnu. Ok for trunk?

Cheers,
Janus


2016-12-02  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/43207
    * primary.c (gfc_match_varspec): Reject nonpolymorphic references to
    abstract types.

2016-12-02  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/43207
    * gfortran.dg/abstract_type_9.f90: New test case.

Attachment: pr43207.diff
Description: Text document

! { dg-do compile }
!
! PR 43207: [OOP] invalid (pointer) assignment to and from abstract non-polymorphic expressions
!
! Contributed by Tobias Burnus <burnus@gcc.gnu.org>

  implicit none
  type, abstract :: parent
    integer :: i
  end type
  type, extends(parent) :: child
    class(parent), pointer :: comp
  end type

  type(child), target :: c1
  class(child), allocatable :: c2
  class(parent), pointer :: cp

  c1%parent = c1%parent  ! { dg-error "Nonpolymorphic reference to abstract type" }
  c2%parent = c1%parent  ! { dg-error "Nonpolymorphic reference to abstract type" }

  cp => c1%comp
  cp => c1%parent        ! { dg-error "Nonpolymorphic reference to abstract type" }

  call sub(c1%comp)
  call sub(c1%parent)    ! { dg-error "Nonpolymorphic reference to abstract type" }

contains

  subroutine sub(arg)
    class(parent) :: arg
  end subroutine

end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]