User account creation filtered due to spam.

Bug 33215 - Bind(C): Bugs with empty "name=": Creates wrong result and accepts invalid
Summary: Bind(C): Bugs with empty "name=": Creates wrong result and accepts invalid
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: accepts-invalid, rejects-valid
Depends on:
Blocks: 32630
  Show dependency treegraph
Reported: 2007-08-28 09:20 UTC by Tobias Burnus
Modified: 2007-08-29 13:36 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2007-08-28 14:30:09


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-08-28 09:20:51 UTC
The following program should give an error message as NAG f95 does:

Error: a.f90, line 4: Only one entity allowed with BIND(C,NAME=...)

gfortran currently happily accepts this.

module m
  use iso_c_binding
  implicit none
  integer(c_int), bind(C, name="") :: a,b
end module m
Comment 1 Tobias Burnus 2007-08-28 10:04:08 UTC
The bug is actually worse as valid Fortran 2003 programs are rejected.

The following program should print "5 -5". The two static global variables are not the same as their binding name is not "a" but something like "__m_MOD_a" and "__n_MOD_a".

Somehow the binding is treated wrongly and thus one gets the error:

Error: Binding label 'a' at (1) collides with global entity 'a' at (2)

With NAG f95 the desired "5 -5" is printed. The program below should behave identically for BIND(C,name="") and without. (Using the variable from C is difficult, but one could think of passing the variable as actual argument or - with TARGET attribute - a pointer to that variable.)

module m
  use iso_c_binding
  implicit none
  integer(c_int), save, bind(C, name="") :: a = 5
!  integer(c_int), save :: a = 5
end module m

module n
  use iso_c_binding
  implicit none
  integer(c_int), save, bind(C,name="") :: a = -5
!  integer(c_int), save :: a = -5
end module n

program prog
use m
use n, b=>a
implicit none
  print *, a, b
end program prog
Comment 2 2007-08-29 00:14:50 UTC
Subject: Bug number PR 33215

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
Comment 3 Tobias Burnus 2007-08-29 13:09:25 UTC
Subject: Bug 33215

Author: burnus
Date: Wed Aug 29 13:08:55 2007
New Revision: 127898

2007-08-29  Christopher D. Rickett  <>

	PR fortran/33215
	* decl.c (build_sym): Pass number of identifiers on line to
	(set_binding_label): Verify that only one identifier given if
	NAME= specified, even if the given binding label has zero length.
	(gfc_match_bind_c): Remove declaration for has_name_equals because
	it hides the static global one that is needed.

2007-08-29  Christopher D. Rickett  <>

	PR fortran/33215
	* gfortran.dg/binding_label_tests_15.f03: New test case.
	* gfortran.dg/binding_label_tests_16.f03: Ditto.


Comment 4 Tobias Burnus 2007-08-29 13:36:27 UTC