https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68433
Bug ID: 68433 Summary: Wrong code with INTERFACE, INTRINSIC, and optional arguments Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: dominiq at lps dot ens.fr Target Milestone: --- While investigating pr46846, I found that the following code program ainttest implicit none intrinsic aint intrinsic index intrinsic len intrinsic nint real r character c, string2 character(7) string1 integer i r = 3.14 c = 'A' string2 = 'n' string1 = 'string1' i = 13 call rsub('aint',aint,r) call rsubi('nint',nint,r) call char2isub('index',index,string1,string2) call charstarisub('len',len,string1) end program ainttest subroutine rsub(label,fun,x) implicit none character(*) label interface function fun(x,k) implicit none integer, intent(in), optional :: k real, intent(in) :: x real fun end function fun end interface real x write(*,*) label//'(',x,') = ',fun(x,k=8) print *, "expected:", aint(x,kind=8) end subroutine rsub subroutine rsubi(label,fun,x) implicit none character(*) label interface function fun(x,k) implicit none integer, intent(in), optional :: k real, intent(in) :: x integer fun end function fun end interface real x write(*,*) label//'(',x,') = ',"'",fun(x,k=2),"'" print *, "expected:","'",nint(x,kind=2),"'" end subroutine rsubi subroutine char2isub(label,fun,x,y) implicit none character(*) label,x,y interface function fun(x,y,l,k) implicit none logical, intent(in), optional :: l integer, intent(in), optional :: k character(*), intent(in) :: x,y integer fun end function fun end interface write(*,*) label//'(',x,',',y,') = ',fun(x,y) print *, "expected:", index(x,y) end subroutine char2isub subroutine charstarisub(label,fun,x) implicit none character(*) label,x write(*,*) label//'(',x,') = ',fun(x) print *, "expected:", len(x) end subroutine charstarisub while silencing the spurious warnings, generates a wrong code, the output being: aint( 3.14000010 ) = 3.00000000 expected: 3.0000000000000000 nint( 3.14000010 ) = ' 3 ' expected:' 3 ' index(string1,n) = 1 expected: 5 len(string1) = 0 expected: 7 Note that I am not 100% sure that the above code is valid.