Created attachment 50532 [details] program uses interface and module procedure to select between subroutines with type C_PTR and C_FUNPTR The attached program always selects the TYPE(C_FUNPTR) when selecting between a (overloaded) subroutine with TYPE(C_PTR) and TYPE(C_FUNPTR), even when the variable type is TYPE(C_PTR). It does this for both passing a variable as the argument or using the C_LOC or c_funloc directly in the call. I tried it with 7.5.0, 10.2.0, same behavior. Intel and NAG both select the correct subroutine.
I checked with gcc master (4/20/2021), and it still has the same issue.
I noticed the problem when building CGNS with gfortran / Gcc 10.2.0, and now with Gcc 10.3.2 the issue disappeared.
(In reply to Thierry Thomas from comment #2) > I noticed the problem when building CGNS with gfortran / Gcc 10.2.0, and now > with Gcc 10.3.2 the issue disappeared. No. The reported problem still exists. Output for the attached testcase: cg_configure_funptr cg_configure_funptr cg_configure_funptr cg_configure_funptr Expected: cg_configure_ptr cg_configure_funptr cg_configure_ptr cg_configure_funptr
Is there an update on this issue, the CGNS fortran wrappers will not work with gfortran as there are no work arounds for this issue. Thanks.
I removed the c_funptr interface in CGNS since it was not being used.
Patch: https://gcc.gnu.org/pipermail/fortran/2023-April/059166.html
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:c482995cc5bac4a2168ea0049041e712544e474b commit r13-7145-gc482995cc5bac4a2168ea0049041e712544e474b Author: Harald Anlauf <anlauf@gmx.de> Date: Tue Apr 11 16:44:32 2023 +0200 Fortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615,PR99982] gcc/fortran/ChangeLog: PR fortran/61615 PR fortran/99982 * interface.cc (compare_parameter): Enable type and rank checks for arguments of derived type from the intrinsic module ISO_C_BINDING. gcc/testsuite/ChangeLog: PR fortran/61615 PR fortran/99982 * gfortran.dg/interface_49.f90: New test.
Fixed on mainline for gcc-13.
This is Great! Thank-you.
The releases/gcc-12 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:62a4f2fb356cab8cfebfeeac2895b657c32b8dd4 commit r12-9467-g62a4f2fb356cab8cfebfeeac2895b657c32b8dd4 Author: Harald Anlauf <anlauf@gmx.de> Date: Tue Apr 11 16:44:32 2023 +0200 Fortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615,PR99982] gcc/fortran/ChangeLog: PR fortran/61615 PR fortran/99982 * interface.cc (compare_parameter): Enable type and rank checks for arguments of derived type from the intrinsic module ISO_C_BINDING. gcc/testsuite/ChangeLog: PR fortran/61615 PR fortran/99982 * gfortran.dg/interface_49.f90: New test. (cherry picked from commit c482995cc5bac4a2168ea0049041e712544e474b)
Thanks for the standard reference. That is indeed what I was looking for. I understand now that, in this case, the INTENT refers to whether C_PTR can be changed and does not relate to the INTENT state of the target. I should change all my usage cases to INTENT(IN) since none of the Fortran wrappers allow changes to the pointer itself.