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, F08] PR 54756: Should reject CLASS, intent(out) in PURE procedures


Hi all,

after committing my recent patch for PR 64209, I realized that the
accompanying test case is actually invalid in one aspect and that
there is already a PR (and patch) for that problem: PR 54756. It's
about F08 forbidding polymorphic INTENT(OUT) arguments in pure
procedures. The reason for this restriction is essentially that a
finalizer (if present) would need to be called for such an argument,
and the finalizer could be impure (which in general can not be checked
at compile time). The constraint technically only exists in F08 and
not in F03, but my patch unconditionally rejects such code.

In fact the patch uncovered a good number of cases in the testsuite,
which are invalid in this respect. I fixed all of them by making the
encompassing procedure impure. After that the patch regtests cleanly.
Ok for trunk?

Cheers,
Janus


2014-12-19  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/54756
    * resolve.c (resolve_formal_arglist): Reject polymorphic INTENT(OUT)
    arguments of pure procedures.

2014-12-19  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/54756
    * gfortran.dg/class_array_3.f03: Fixed invalid test case.
    * gfortran.dg/class_array_7.f03: Ditto.
    * gfortran.dg/class_dummy_4.f03: Ditto.
    * gfortran.dg/defined_assignment_3.f90: Ditto.
    * gfortran.dg/defined_assignment_5.f90: Ditto.
    * gfortran.dg/elemental_subroutine_10.f90: Ditto.
    * gfortran.dg/typebound_operator_4.f03: Ditto.
    * gfortran.dg/typebound_proc_16.f03: Ditto.
    * gfortran.dg/unlimited_polymorphic_19.f90: Ditto.
    * gfortran.dg/class_dummy_5.f90: New test.

Attachment: pr54756.diff
Description: Text document

! { dg-do compile }
!
! PR 54756: [OOP] [F08] Should reject CLASS, intent(out) in PURE procedures
!
! Contributed by Tobias Burnus <burnus@gcc.gnu.org>

module m
  type t
  contains
    final :: fnl   ! impure finalizer
  end type t
contains
  impure subroutine fnl(x)
    type(t) :: x
    print *,"finalized!"
  end subroutine
end

program test
  use m
  type(t) :: x
  call foo(x)
contains
  pure subroutine foo(x)  ! { dg-error "may not be polymorphic" }
    ! pure subroutine would call impure finalizer
    class(t), intent(out) :: x
  end subroutine
end

! { dg-final { cleanup-modules "m" } }

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