From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0FEE53858C52; Fri, 14 Oct 2022 22:45:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FEE53858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665787527; bh=gbQKKtDUsMCZn6kpfp6JTkfmwosRUrIpbKhzJY7Uj2U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TmAmAUk2fOE2pfRvT4UeHtmE9h1HQ/InQCc52d42BktsyFtbL5TKC6TZPAXsCpykt uQzltqbLIxUHpAIH9+blLdDSzPbW0Xwk55KPdh8DShABUHyFlfOYN15cT00b+rc6RU QpSMySqTHXPBNmzI0afRlTAwyfGpd7u/0YOtx+ys= From: "kargl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBmb3J0cmFuLzEwNzI2Nl0gUmVqZWN0IGtpbmQ9NCBjaGFy?= =?UTF-8?B?YWN0ZXJzIGZvciBCSU5EKEMpIOKAkyBpdCBpbnZhbGlkIGFuZCBnZW5lcmF0?= =?UTF-8?B?ZXMgd3JvbmcgY29kZQ==?= Date: Fri, 14 Oct 2022 22:45:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: accepts-invalid, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107266 --- Comment #7 from kargl at gcc dot gnu.org --- Here's the updated patch. It will accept the code as before if -std=3D is = absent or -std=3DGNU. For other -std=3D flags such as -std=3Df2018, one will get % gfcx -c -std=3Df2018 a.f90 a.f90:1:31: 1 | function f(x) bind(C) result(a) | 1 2 | character(kind=3D4) a | 2=20=20=20=20=20=20=20=20=20=20=20 Error: GNU Extension: Function result variable 'a' at (1) with type CHARACTER(KIND=3D4) at (2) cannot have the BIND(C) attribute a.f90:7:28: 7 | character(kind=3D4) function g(x) bind(C) | 1 Error: GNU Extension: Symbol 'g' at (1) with type CHARACTER(KIND=3D4) canno= t have the BIND(C) attribute diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index d133bc2d034..db28cd05365 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -15509,6 +15509,29 @@ resolve_symbol (gfc_symbol *sym) return; } + /* A Function result with character(kind=3D4) 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 =3D=3D BT_CHARACTER + && sym->result->ts.kind !=3D gfc_default_character_kind + && !gfc_notify_std (GFC_STD_GNU, "Symbol %qs at %L with type " + "CHARACTER(KIND=3D4) cannot have the BIND(C) " + "attribute", sym->name, &sym->declared_at)) + return; + + if (sym->ts.type =3D=3D BT_UNKNOWN + && sym->result + && sym->result->ts.type =3D=3D BT_CHARACTER + && sym->result->ts.kind !=3D gfc_default_character_kind + && !gfc_notify_std (GFC_STD_GNU, "Function result variable %qs at= " + "%L with type CHARACTER(KIND=3D4) at %L canno= t " + "have the BIND(C) attribute", sym->result->na= me, + &sym->result->declared_at, + &sym->result->ts.u.cl->length->where)) + return; + } + if (sym->attr.artificial) return;=