https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117643
--- Comment #21 from anlauf at gcc dot gnu.org --- (In reply to anlauf from comment #20) Replying to myself: > So if I come from the other side, which code to accept and which to diagnose, > I tried: > > if (string->ts.type != BT_CHARACTER > || string->ts.kind != 1 > || (string->expr_type == EXPR_VARIABLE && !string->ts.is_c_interop)) > > and threw it on: > > subroutine sub1 (s) > character(*), intent(in) :: s > print *, f_c_string (s) ! detected > print *, f_c_string (trim(s)) ! not detected > end > > subroutine sub2 (s) > character(kind=c_char,len=*), intent(in) :: s > print *, f_c_string (s) ! OK > print *, f_c_string (trim(s)) ! OK > end > > I tried to extend to above conditions to > .. (string->expr_type == EXPR_VARIABLE || string->expr_type == > EXPR_FUNCTION) .. > but it appears that TRIM() keeps only the kind parameter, and when the > argument > is of kind C_CHAR the result string looses the interoperability attribute. The latter issue is fixed by the following patch (obvious but not regtested): diff --git a/gcc/fortran/iresolve.cc b/gcc/fortran/iresolve.cc index 580f8c8407d..759eb99a645 100644 --- a/gcc/fortran/iresolve.cc +++ b/gcc/fortran/iresolve.cc @@ -3192,6 +3200,7 @@ gfc_resolve_trim (gfc_expr *f, gfc_expr *string) { f->ts.type = BT_CHARACTER; f->ts.kind = string->ts.kind; + f->ts.is_c_interop = string->ts.is_c_interop; f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind); }