The following is legal: function x(z) bind(C,name='x'//'f') integer :: z, x end function x as the Standard (F2003) only says: R509: language-binding-spec is BIND (C [, NAME = scalar-char-initialization-expr ]) C540: The scalar-char-initialization-expr shall be of default character kind. So, any scalar char initialisation expression of default character kind is fair game. This will require removing a good part of the code in gfc_match_bind_c(), and call more generic routines instead, so it's not really bad news (and it also requires remove the gfc_match_name_C function).
And there is more to it (with import statements), see the rest of the thread at http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/148d078cda002dc1#
The other problem mentioned in the thread is the following bogus warning: procedure(stub), bind(C,name='cacosf') :: my_ACOS ! Compiles 1 Warning: Variable 'my_acos' at (1) may not be a C interoperable kind but it is bind(c) I think it appeared after 2008-05-01-Rev134843 and should be related to one of the procedure patches. Test case: module trig_sp use ISO_C_BINDING integer, parameter :: rkind = C_FLOAT integer, parameter :: ckind = C_FLOAT_COMPLEX abstract interface function stub(z) bind(C) import rkind, ckind complex(ckind), value :: z complex(ckind) stub end function stub end interface procedure(stub), bind(C,name='cacosf') :: my_ACOS ! Compiles end module trig_sp
The problem in comment #2 was indeed introduced by my rev. 134867, and can be fixed by the following patch: Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 136130) +++ gcc/fortran/resolve.c (working copy) @@ -7751,6 +7751,7 @@ resolve_symbol (gfc_symbol *sym) { sym->ts.type = sym->ts.interface->ts.type; sym->ts.kind = sym->ts.interface->ts.kind; + sym->ts.is_c_interop = sym->ts.interface->ts.is_c_interop; sym->attr.function = sym->ts.interface->attr.function; sym->attr.subroutine = sym->ts.interface->attr.subroutine; copy_formal_args (sym, sym->ts.interface);
Subject: Bug 36275 Author: janus Date: Wed Jun 4 21:04:32 2008 New Revision: 136372 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136372 Log: 2008-06-04 Janus Weil <janus@gcc.gnu.org> PR fortran/36322 PR fortran/36275 * resolve.c (resolve_symbol): Correctly copy the interface for a PROCEDURE declaration. 2008-06-04 Janus Weil <janus@gcc.gnu.org> PR fortran/36322 PR fortran/36275 * gfortran.dg/proc_decl_2.f90: Extended. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/proc_decl_2.f90
Rev. 136372 fixes the issue from comment #2 (but not the original test case in comment #0).
Created attachment 16215 [details] proposed patch With this patch the first testcase compiles with two warnings. It doesn't handle import statements as it is far less trivial ;) I'll have to see more in details what was said on the c.l.f thread. Awaiting constructive (or destructive if you prefer) comments, advices, screams, ...
*** Bug 38838 has been marked as a duplicate of this bug. ***
PR38838 has additional testcases: subroutine test() bind(c, name=trim("Hello ")) end and subroutine test() bind(c, name=1_"name") end
See also PR38839 for expanded character set.
Note that arbitrary long binding names have been implemented in the meantime (PR51808). A fix for this PR should obviously maintain that feature (which Mikael's patch in comment 6 does not seem to do).
Patch proposed here, somewhat based on Mikael's patch in comment #6: https://gcc.gnu.org/ml/fortran/2014-06/msg00090.html
Author: fxcoudert Date: Sun Jun 29 14:14:16 2014 New Revision: 212123 URL: https://gcc.gnu.org/viewcvs?rev=212123&root=gcc&view=rev Log: PR fortran/36275 PR fortran/38839 * decl.c (check_bind_name_identifier): New function. (gfc_match_bind_c): Match any constant expression as binding label. * match.c (gfc_match_name_C): Remove. * gfortran.dg/binding_label_tests_2.f03: Adjust error messages. * gfortran.dg/binding_label_tests_27.f90: New file. Added: trunk/gcc/testsuite/gfortran.dg/binding_label_tests_27.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/fortran/match.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/binding_label_tests_2.f03
Fixed on trunk.