From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id D21EE3858002; Tue, 20 Dec 2022 21:24:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D21EE3858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671571475; bh=XpYKm/29oVMy/pCzKj+ijzZ+N9zI8ubkcWjlfUJcSAE=; h=From:To:Subject:Date:From; b=PSeRX8tOZf6UjFTQsJX+XbyTNq7bdkzTvIjrT1qFevt7CjIYfVVwdK2g6vZfeYnIN ZfnrbI1yyBBpgnNrhVwJpz4qAwPfMUG3SEforstsUrgHqdqeCNvuExWl3Ni+E5Xthb 0dcFjINSo3itPcRN4iXY0IpKEL42Y1Qdmb0g0nM0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4809] Fortran: a C interoperable function cannot have the CLASS attribute [PR95375] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/master X-Git-Oldrev: a6504f13a0509f3937bdcdf63bf76bed7d880b72 X-Git-Newrev: aed5584ff6891560dc567e54517b9722dadc503e Message-Id: <20221220212435.D21EE3858002@sourceware.org> Date: Tue, 20 Dec 2022 21:24:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:aed5584ff6891560dc567e54517b9722dadc503e commit r13-4809-gaed5584ff6891560dc567e54517b9722dadc503e Author: Harald Anlauf Date: Tue Dec 20 21:17:08 2022 +0100 Fortran: a C interoperable function cannot have the CLASS attribute [PR95375] gcc/fortran/ChangeLog: PR fortran/95375 * decl.cc (verify_bind_c_sym): Extend interoperability check to CLASS variables. gcc/testsuite/ChangeLog: PR fortran/95375 * gfortran.dg/bind_c_procs_4.f90: New test. Diff: --- gcc/fortran/decl.cc | 12 ++++++++---- gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 1562dc22bc6..e593518a77e 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -5998,10 +5998,14 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts, } else { - if (tmp_sym->ts.type == BT_DERIVED || ts->type == BT_DERIVED) - gfc_error ("Type declaration %qs at %L is not C " - "interoperable but it is BIND(C)", - tmp_sym->name, &(tmp_sym->declared_at)); + if (tmp_sym->ts.type == BT_DERIVED || ts->type == BT_DERIVED + || tmp_sym->ts.type == BT_CLASS || ts->type == BT_CLASS) + { + gfc_error ("Type declaration %qs at %L is not C " + "interoperable but it is BIND(C)", + tmp_sym->name, &(tmp_sym->declared_at)); + retval = false; + } else if (warn_c_binding_type) gfc_warning (OPT_Wc_binding_type, "Variable %qs at %L " "may not be a C interoperable " diff --git a/gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 b/gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 new file mode 100644 index 00000000000..407d8bb9afc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! PR fortran/95375 - ICE in add_use_op +! Contributed by G.Steinmetz + +function f() result(n) bind(c) ! { dg-error "not C interoperable" } + class(*), allocatable :: n +end +program p + interface + function f() result(n) bind(c) + integer :: n + end + end interface + if ( f() /= 0 ) stop +end + +! { dg-prune-output "Type mismatch" }