https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100551
--- Comment #4 from anlauf at gcc dot gnu.org ---
Playing with the testcase show that the patch in comment#3 is incomplete.
Next try:
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index cce18d094a6..3de53009970 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -5826,7 +5826,9 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
&derived_array);
}
else if (UNLIMITED_POLY (fsym) && e->ts.type != BT_CLASS
- && gfc_expr_attr (e).flavor != FL_PROCEDURE)
+ && e->ts.type != BT_PROCEDURE
+ && (gfc_expr_attr (e).flavor != FL_PROCEDURE
+ || (gfc_expr_attr (e).proc != PROC_UNKNOWN)))
{
/* The intrinsic type needs to be converted to a temporary
CLASS object for the unlimited polymorphic formal. */
This makes the following case work again:
program p
implicit none
integer :: result
result = 1
result = test ( (result)) ! works
if (result /= 1) stop 1
result = test (int (result)) ! issue 1
write(*,*) result
result = test (f (result)) ! issue 2
write(*,*) result
contains
integer function test(x)
class(*), intent(in) :: x
select type (x)
type is (integer)
test = x
class default
test = -1
end select
end function test
integer function f(x)
integer, intent(in) :: x
f = 2*x
end function f
end program