else
gfc_free_expr (tmp);
}
+ else if (newAssoc->target->ts.type == BT_UNKNOWN
+ && newAssoc->target->expr_type == EXPR_OP)
+ {
+ /* The selector is an unresolved expression involving an overloaded
+ intrinsic operator (e.g. a `+' bound via an explicit interface
+ to a function returning CHARACTER). Try to extend it now, the
+ same way the type-bound user-defined operator case above does
+ for INTRINSIC_USER, so the associate name gets a usable type
+ before the body of the ASSOCIATE construct is parsed. */
+ gfc_expr *tmp = gfc_copy_expr (newAssoc->target);
+ if (gfc_extend_expr (tmp) == MATCH_YES)
+ gfc_replace_expr (newAssoc->target, tmp);
+ else
+ gfc_free_expr (tmp);
+ }
/* The `variable' field is left blank for now; because the target is not
yet resolved, we can't use gfc_has_vector_subscript to determine it
--- /dev/null
+! { dg-do run }
+!
+! PR fortran/125650
+!
+! Verify that an ASSOCIATE selector that is an overloaded intrinsic operator
+! expression (here a CHARACTER-returning `+', bound via an explicit
+! interface) is extended to a function call early enough that the
+! associate name receives a known type before the body of the ASSOCIATE
+! construct is parsed. Previously the associate name stayed untyped,
+! a substring reference to it was matched incorrectly, and the wrong
+! reference reached the back end, causing an ICE in trans-expr.cc.
+
+module associate_81_m
+ implicit none
+
+ interface operator(+)
+ module procedure concat
+ end interface
+
+contains
+
+ function concat (dd1, dd2)
+ implicit none
+ character(len = 8) :: concat
+ character(len = 3), intent(in) :: dd1
+ character(len = 5), intent(in) :: dd2
+ concat = dd1 // dd2
+ end function
+
+end module
+
+program associate_81
+ use associate_81_m
+ implicit none
+
+ character(len = 3) :: arg1 = 'aaa'
+ character(len = 5) :: arg2 = 'ccccc'
+
+ associate (aa => arg1, bb => arg2, cc => arg1 + arg2)
+ if (cc /= 'aaaccccc') stop 1
+ if (cc(3:5) /= 'acc') stop 2
+ end associate
+
+end program