Bug 40920 - Derived type with BIND(C) - rejected as argument.
Summary: Derived type with BIND(C) - rejected as argument.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 32630
  Show dependency treegraph
 
Reported: 2009-07-30 21:32 UTC by Tobias Burnus
Modified: 2013-06-25 09:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-07-30 21:32:55 UTC
Found at http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/220286db98888bb4#

The following program is rejected with the bogus message that the derived type is not interoperable - it works if one moves the type declaration out of the interface statement. It also works with SEQUENCE instead of BIND(C).


                RESULTAT, SIGNE) bind(C, name='gsl_sf_lngamma_sgn_e_wrapper')
                        1
Error: Type 'resultat' at (1) is a parameter to the BIND(C)  procedure
'gsl_sf_lngamma_sgn_e_wrapper' but is not C interoperable because
derived type 'gsl_sf_result' is not C interoperable.


!            use iso_c_binding
!            type, bind(C) :: GSL_SF_RESULT
!                real(c_double)          VALEUR
!                real(c_double)          ERREUR
!            end type
    interface
        integer(c_int) function gsl_sf_lngamma_sgn_e_wrapper(X, &
                RESULTAT, SIGNE) bind(C, name='gsl_sf_lngamma_sgn_e_wrapper')
            use iso_c_binding
!            import :: GSL_SF_RESULT
            implicit none
            type, bind(C) :: GSL_SF_RESULT
                real(c_double)          VALEUR
                real(c_double)          ERREUR
            end type
            real(c_double), intent(in) ::               X
            type(GSL_SF_RESULT), intent(out) ::         RESULTAT
            real(c_double), intent(out) ::              SIGNE
        end function
    end interface
    end
Comment 1 Tobias Burnus 2009-08-03 09:53:05 UTC
Could not find the problem so far, cf. symbol.c's verify_bind_c_derived_type as starting point.

 * * *

The following TODO should be checked; I heard it is invalid C99 (as per grammar in 6.7.2.1 Structure and union specifiers) but valid C++. One should check it in the F2003 (F2008 draft?) as this the definite source.

  /* TODO: is this really an error?  */
  if (curr_comp == NULL)
    {
      gfc_error ("Derived type '%s' at %L is empty",
		 derived_sym->name, &(derived_sym->declared_at));
      return FAILURE;
    }
Comment 2 kargl 2010-01-13 00:43:48 UTC
A related issue has been reported here

http://groups.google.com/group/comp.lang.fortran/browse_frm/thread
/ddc211f2987326b8#

in particular the error message needs to be rewritten.

Error: Type 'resultat' at (1) is a parameter to the BIND(C)  procedure
'gsl_sf_lngamma_sgn_e_wrapper' but is not C interoperable because
derived type 'gsl_sf_result' is not C interoperable.

resultat is not a type, and it most definitely is not a parameter.

Possible wording

Error:  Argument 'resultat' at (1) to the BIND(C) procedure
'gsl_sf_lngamma_sgn_e_wrapper' is not ...
Comment 3 Tobias Burnus 2010-01-13 08:44:57 UTC
(In reply to comment #2)
> A related issue has been reported here
> http://groups.google.com/group/comp.lang.fortran/browse_frm/thread/ddc211f2987326b8#

That example is invalid and correctly rejected; if one makes it valid, one is back at the bug shown in comment 0. But I agree that the message text is bad:

--- decl.c      (revision 155850)
+++ decl.c      (working copy)
@@ -936,2 +936,2 @@ verify_c_interop_param (gfc_symbol *sym)
-               gfc_error ("Type '%s' at %L is a parameter to the BIND(C) "
-                          " procedure '%s' but is not C interoperable "
+               gfc_error ("Dummy argument '%s' at %L of BIND(C) "
+                          "procedure '%s' is not C interoperable "

(Your "Argument .. to procedure" sounds for me as if an "actual argument" were meant.)
Comment 4 Dominique d'Humieres 2013-06-25 09:22:00 UTC
AFAICT this PR has been fixed from 4.6 up to trunk (4.9). Closing as FIXED. Please reopen if I am missing something.