Files
Peter Klausler 455de5543c [flang] Fix non-portable TYPE(*) usage in generic (#176235)
Fortran allows a scalar actual argument of any type to correspond with a
TYPE(*) dummy argument that is an assumed-size array. This usage isn't
portable, and it didn't work with a generic procedure with this
compiler, only specific procedures. It affected at least one API in
OpenMPI.

Fix generic resolution to allow for this case, add a distinguishability
test to detect generic interfaces that have ambiguous specific
procedures due to it, and add an optional portability warning (off by
default).
2026-01-19 11:00:26 -08:00

33 lines
1.1 KiB
Fortran

!RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
module m
interface generic1 ! ok
module procedure :: sub1
end interface
!ERROR: Generic 'generic2' may not have specific procedures 'sub1' and 'sub2' as their interfaces are not distinguishable
interface generic2
module procedure :: sub1, sub2
end interface
contains
subroutine sub1(a,len)
type(*), intent(in) :: a(*)
integer len
print *, 'in sub'
end
subroutine sub2(a,len)
character(*), intent(in) :: a
integer len
print *, 'in sub2'
end
end
program test
use m
character(3) :: foo = "abc"
!PORTABILITY: A scalar actual argument for an assumed-size TYPE(*) dummy is not portable [-Wassumed-type-size-dummy]
call sub1(foo, 3) ! ok
!PORTABILITY: A scalar actual argument for an assumed-size TYPE(*) dummy is not portable [-Wassumed-type-size-dummy]
call generic1(foo, 3) ! ok
!ERROR: The actual arguments to the generic procedure 'generic2' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
call generic2(foo, 3)
end