public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "everythingfunctional at protonmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/113338] New: Valid Code Rejected, bind(C) procedure with pointer argument
Date: Thu, 11 Jan 2024 18:48:03 +0000 [thread overview]
Message-ID: <bug-113338-4@http.gcc.gnu.org/bugzilla/> (raw)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113338
Bug ID: 113338
Summary: Valid Code Rejected, bind(C) procedure with pointer
argument
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: everythingfunctional at protonmail dot com
Target Milestone: ---
The following example is rejected by gfortran, but should be valid.
Fortran Program:
program example
use iso_c_binding
implicit none
type :: t
integer :: i
end type
interface
subroutine c_proc(x) bind(c)
import t
implicit none
type(t), pointer, intent(in) :: x
end subroutine
end interface
type(t), target :: x
x%i = 42
call c_proc(x)
contains
subroutine f_proc(x) bind(c)
type(t), pointer, intent(in) :: x
print *, x%i
end subroutine
end program
C code:
#include <ISO_Fortran_binding.h>
extern void f_proc(CFI_cdesc_t* x);
extern void c_proc(CFI_cdesc_t* x)
{
f_proc(x);
}
Is rejected with the following messages:
main.f90:11:27:
11 | subroutine c_proc(x) bind(c)
| 1
Error: Variable ‘x’ at (1) is a dummy argument to the BIND(C) procedure
‘c_proc’ but is not C interoperable because derived type ‘t’ is not C
interoperable
main.f90:23:23:
23 | subroutine f_proc(x) bind(c)
| 1
Error: Variable ‘x’ at (1) is a dummy argument to the BIND(C) procedure
‘f_proc’ but is not C interoperable because derived type ‘t’ is not C
interoperable
But the standard says:
> A Fortran procedure interface is interoperable with a C function prototype if
> ...
> (5) any dummy argument without the VALUE attribute corresponds to a formal parameter of the prototype that is of a pointer type, and either
> ...
> * the dummy argument is allocatable, assumed-shape, assumed-rank, or a pointer without the CONTIGUOUS attribute, and the formal parameter is a pointer to CFI_cdesc_t
I.e., that argument need not be interoperable, because it has the pointer
attribute.
next reply other threads:[~2024-01-11 18:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 18:48 everythingfunctional at protonmail dot com [this message]
2024-01-11 19:56 ` [Bug fortran/113338] " anlauf at gcc dot gnu.org
2024-01-12 1:51 ` everythingfunctional at protonmail dot com
2024-01-12 20:23 ` [Bug fortran/113338] [F2018] " anlauf at gcc dot gnu.org
2024-01-29 17:59 ` anlauf at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-113338-4@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).