https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107266
kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2022-10-14 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #4 from kargl at gcc dot gnu.org --- This un-regression-tested patch diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index d133bc2d034..dfd59febf70 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -15509,6 +15509,33 @@ resolve_symbol (gfc_symbol *sym) return; } + /* A Function result with character(kind=4) cannot have the bind(c) + attribute, because c_char is assumed to match default character kind. */ + if (sym->attr.function && sym->attr.is_bind_c) + { + if (sym->ts.type == BT_CHARACTER + && sym->result->ts.kind != gfc_default_character_kind) + { + gfc_error ("Symbol %qs at %L with type CHARACTER(KIND=4) " + "cannot have the BIND(C) attribute", sym->name, + &sym->declared_at); + return; + } + + if (sym->ts.type == BT_UNKNOWN + && sym->result + && sym->result->ts.type == BT_CHARACTER + && sym->result->ts.kind != gfc_default_character_kind) + { + gfc_error ("Function result variable %qs at %L with type " + "CHARACTER(KIND=4) at %L cannot have the BIND(C) " + "attribute", + sym->result->name, &sym->result->declared_at, + &sym->result->ts.u.cl->length->where); + return; + } + } + if (sym->attr.artificial) return; with this code function f(x) bind(C) result(a) character(kind=4) a character(kind=4), value :: x a = x end character(kind=4) function g(x) bind(C) character(kind=4), value :: x g = x end yields % gfcx -c a.f90 a.f90:1:31: 1 | function f(x) bind(C) result(a) | 1 2 | character(kind=4) a | 2 Error: Function result variable 'a' at (1) with type CHARACTER(KIND=4) at (2) cannot have the BIND(C) attribute a.f90:7:28: 7 | character(kind=4) function g(x) bind(C) | 1 Error: Symbol 'g' at (1) with type CHARACTER(KIND=4) cannot have the BIND(C) attribute Tobias, once you regression test the patch, feel free to commit it.