<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111021>111021</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] incorrect diagnostic of type-bound-generic-stmt in defined I/O
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kkwli
</td>
</tr>
</table>
<pre>
Flang flags the code as error if the _type-bound-generic-stmt_ is omitted in the child type.
Reproducer:
```fortran
module m
type base
character(3) :: c = 'xxx'
contains
procedure, pass :: write => writebase
generic :: write(formatted) => write
end type
type, extends(base) :: child
integer(4) :: i = -999
contains
procedure, pass :: write => writechild
! generic :: write(formatted) => write
end type
contains
subroutine writebase(dtv, unit, iotype, v_list, iostat, iomsg)
class(base), intent(in) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
write(unit, *, iostat=iostat, iomsg=iomsg) dtv%c
iomsg = 'dtiobasewrite'
end subroutine
subroutine writechild(dtv, unit, iotype, v_list, iostat, iomsg)
class(child), intent(in) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
write(unit, *, iostat=iostat, iomsg=iomsg) dtv%c, dtv%i
iomsg = 'dtiochildwrite'
end subroutine
end module
program main
use m
class(child), pointer :: c1
character(40) :: msg
allocate(c1, source=child('abc', 2024))
write(*, "(DT)") c1
end program
```
Compile output:
```
$ flang-new d.f90
error: Semantic errors in d.f90
./d.f90:42:20: error: Derived type 'child' in I/O may not be polymorphic unless using defined I/O
write(*, "(DT)") c1
^^
```
A similar case that no error is flagged.
```fortran
module m
type base
contains
procedure, nopass :: f => f1
generic :: g => f
end type
type, extends(base) :: child
contains
procedure, nopass :: f => f2
! generic :: g => f
end type
contains
subroutine f1()
print *, 'f1 ...'
end subroutine
subroutine f2()
print *, 'f2 ...'
end subroutine
end module
program specific004
use m
class(child), pointer :: c1
allocate(c1)
call c1%g()
end program
```
Output:
```
f2 ...
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V11vozoT_jXOzSgRDGQJF7nI22yk92qlc879ypiB-CzYyDbd9t8f2UDittu0q1YbRQk2no_nmWFm4NbKVhHt2fZ_bHtc8dGdtdn_-PGzk6tK14_7U8dVC03HWwvuTCB0TcAtkDHagGzC5nf3ONC60qOq1y0pMlKsrevdd5AWdC-doxqkmhScZVeDF9iw5MiSw_T7Fw1G16Mgw7J5i31Jpm-jjTNcTbu9rseOoJ9WEDRBxS3NG-LMDReODMNdxrAEry87gACWHYFh8fDwwLBYxAGEVo5LZa87AIPRgurREMM7GLi1i5afRjrymlj2dVpEpsNnxv9EgOGu0abnnofJpav8IktqYmVeh0u8A3pwpGrLcBcMRXg8j1fDUjlqA-g8OiQD6HVZlgs7HwMbGWWYfibg6fe5e3asjB6dVBSRjbva3XtfRyWd_5d6Yev-eyftvGcdn6962zIso4h33EaMhkPKkXIMd1JF9Hk7Lxl-7XRw52okykOGh5t2ZgDvMLVILEB3fh1j-5WoHt0TY4GZ9zv6XNzTOUkvsV4CEcQv3GfH50HwO1MwArW4FZHj_s7yjNZOah-d2UAR58w1J17LkilLPy1NZnXvypM_lSR_LkM-kB4An5EheDdfyhvJEmL0nmzxe1MLievOYHRreA89l2qRHm3UZX6VC4P2LJhLQU4vhyPK8iQiJ6KGd50WPHAjUq_N6tEIYtlxyV6GBa-Eh4N3gAnmwewlkAuzM6MMkeHu-E84hN7m4o9HPON71ldjBu50P8iOQI9uGN3LHrwU_dzPAqpdK_oJ9aYp5xthHPAQ_6aeKyfFNCBY3_WjYxuGp2mZHXJk2QH9FVykj2TkPU19wYd25qLwav7P8PQNev4ISjuoCAbdPfbaDGcpYFQdWQujlaqFmhqpqJ4kXubim4wB237139fZOoCVvey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