Files
clang-p2996/flang/test/Semantics/io14.f90
Peter Klausler 49016d53e8 [flang] Silence bogus error message (#111057)
Fortran doesn't permit the use of a polymorphic I/O list item for
intrinsic data transfers, so the compiler emits an error message for
polymorphic items whose types can't possibly be handled by a defined I/O
subroutine. This check didn't allow for the possibility that the defined
I/O subroutine might apply to the parent component of an extended type.

Fixes https://github.com/llvm/llvm-project/issues/111021.
2024-10-07 13:17:28 -07:00

37 lines
1.0 KiB
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1
! Test polymorphic restrictions
module m
type base
end type
type, extends(base) :: t
integer n
contains
procedure :: fwrite
generic :: write(formatted) => fwrite
end type
type, extends(t) :: t2
end type
contains
subroutine fwrite(x, unit, iotype, vlist, iostat, iomsg)
class(t), intent(in) :: x
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: vlist(:)
integer, intent(out) :: iostat
character(*), intent(in out) :: iomsg
write(unit, *, iostat=iostat, iomsg=iomsg) '(', iotype, ':', vlist, ':', x%n, ')'
end subroutine
subroutine subr(x, y, z, w)
class(t), intent(in) :: x
class(base), intent(in) :: y
class(*), intent(in) :: z
class(t2), intent(in) :: w
print *, x ! ok
print *, w ! ok
!ERROR: Derived type 'base' in I/O may not be polymorphic unless using defined I/O
print *, y
!ERROR: I/O list item may not be unlimited polymorphic
print *, z
end subroutine
end