12.6.3p5 requires an I/O data list item to have a defined I/O procedure if it is polymorphic. (We could defer this checking to the runtime, but no other Fortran compiler does so, and we would also have to be able to catch the case of an allocatable or pointer direct component in the absence of a defined I/O subroutine.) Also includes a patch to name resolution that ensures that a SELECT TYPE construct entity is polymorphic in the domain of a CLASS IS guard. Also ensures that non-defined I/O of types with PRIVATE components is caught. Differential Revision: https://reviews.llvm.org/D139050
38 lines
1.0 KiB
Fortran
38 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
|
|
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)
|
|
class(t), intent(in) :: x
|
|
class(base), intent(in) :: y
|
|
class(*), intent(in) :: z
|
|
print *, x ! 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
|
|
|
|
program main
|
|
use m
|
|
call subr(t(123),t(234),t(345))
|
|
end
|