mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 23:36:40 +00:00
[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.
This commit is contained in:
parent
ce5edfd232
commit
49016d53e8
@ -1649,7 +1649,9 @@ bool HasDefinedIo(common::DefinedIo which, const DerivedTypeSpec &derived,
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
// Check for inherited defined I/O
|
||||
const auto *parentType{derived.typeSymbol().GetParentTypeSpec()};
|
||||
return parentType && HasDefinedIo(which, *parentType, scope);
|
||||
}
|
||||
|
||||
void WarnOnDeferredLengthCharacterScalar(SemanticsContext &context,
|
||||
|
@ -9,6 +9,8 @@ module m
|
||||
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
|
||||
@ -19,19 +21,16 @@ module m
|
||||
character(*), intent(in out) :: iomsg
|
||||
write(unit, *, iostat=iostat, iomsg=iomsg) '(', iotype, ':', vlist, ':', x%n, ')'
|
||||
end subroutine
|
||||
subroutine subr(x, y, z)
|
||||
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
|
||||
|
||||
program main
|
||||
use m
|
||||
call subr(t(123),t(234),t(345))
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user