This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fortran, Patch] PR 40110 - allow questionable but standard conform integer(kind=c_char)


Hello,

c_char is a simple parameter (of value 1) and can be used anywhere,
e.g.  in 4.5**c_char.

Properly used it is intended for the type CHARACTER to be interoperable
with C strings of the type "char" (usually treated as "unsigned char").

However, in C "char" is also the smallest integer. Thus the Fortran 2003
standard offers several INTEGER kind parameters for interoperability;
besides, c_int, c_long and several others, there is also "c_signed_char"
(unsigned does not exist in Fortran).

Currently, gfortran rejects
   INTEGER(kind=C_CHAR)
as C_CHAR is misused. However, is C_CHAR's value matches a valid kind
number, there is formally speaking no reason to reject the program. (See
the arguments of Richard Maine in the c.l.f thread, linked from the PR.)

The following patch changes the ERROR into a WARNING, where there is
still the hope that people actually read the warning and act upon it ...

Bootstrapped and regtested on x86-64-linux. OK for the trunk?

Tobias
2009-05-12  Tobias Burnus  <burnus@net-b.de>

	PR fortran/40110
	* decl.c (gfc_match_kind_spec): Turn C kind error into a warning.

2009-05-12  Tobias Burnus  <burnus@net-b.de>

	PR fortran/40110
	* gfortran.dg/bind_c_usage_18.f90: Change dg-error into dg-warning.
	* gfortran.dg/c_kind_tests_2.f03: Ditto.
	* gfortran.dg/interop_params.f03: Ditto.

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 147433)
+++ gcc/fortran/decl.c	(working copy)
@@ -2000,9 +2006,9 @@ kind_expr:
   if (ts->f90_type != BT_UNKNOWN && ts->f90_type != ts->type
       && !((ts->f90_type == BT_REAL && ts->type == BT_COMPLEX)
 	   || (ts->f90_type == BT_COMPLEX && ts->type == BT_REAL)))
-    gfc_error_now ("C kind type parameter is for type %s but type at %L "
-		   "is %s", gfc_basic_typename (ts->f90_type), &where,
-		   gfc_basic_typename (ts->type));
+    gfc_warning_now ("C kind type parameter is for type %s but type at %L "
+		     "is %s", gfc_basic_typename (ts->f90_type), &where,
+		     gfc_basic_typename (ts->type));
 
   gfc_gobble_whitespace ();
   if ((c = gfc_next_ascii_char ()) != ')'
Index: gcc/testsuite/gfortran.dg/bind_c_usage_18.f90
===================================================================
--- gcc/testsuite/gfortran.dg/bind_c_usage_18.f90	(revision 147433)
+++ gcc/testsuite/gfortran.dg/bind_c_usage_18.f90	(working copy)
@@ -7,7 +7,7 @@ subroutine foo(x,y,z,a) bind(c) ! { dg-w
   use iso_c_binding
   implicit none
   integer(4) :: x
-  integer(c_float) :: y ! { dg-error "C kind type parameter is for type REAL" }
+  integer(c_float) :: y ! { dg-warning "C kind type parameter is for type REAL" }
   complex(c_float) :: z ! OK, c_float == c_float_complex
   real(c_float_complex) :: a ! OK, c_float == c_float_complex
 end subroutine foo
@@ -16,8 +16,8 @@ use iso_c_binding
 implicit none
 integer, parameter :: it = c_int
 integer, parameter :: dt = c_double
-complex(c_int), target    :: z1  ! { dg-error "C kind type parameter is for type INTEGER" }
-complex(it), target       :: z2  ! { dg-error "C kind type parameter is for type INTEGER" }
+complex(c_int), target    :: z1  ! { dg-warning "C kind type parameter is for type INTEGER" }
+complex(it), target       :: z2  ! { dg-warning "C kind type parameter is for type INTEGER" }
 complex(c_double), target :: z3  ! OK
 complex(dt), target       :: z4  ! OK
 type(c_ptr) :: ptr
Index: gcc/testsuite/gfortran.dg/c_kind_tests_2.f03
===================================================================
--- gcc/testsuite/gfortran.dg/c_kind_tests_2.f03	(revision 147433)
+++ gcc/testsuite/gfortran.dg/c_kind_tests_2.f03	(working copy)
@@ -4,11 +4,11 @@ module c_kind_tests_2
 
   integer, parameter :: myF = c_float
   real(myF), bind(c) :: myCFloat
-  integer(myF), bind(c) :: myCInt       ! { dg-error "is for type REAL" }
-  integer(c_double), bind(c) :: myCInt2 ! { dg-error "is for type REAL" }
+  integer(myF), bind(c) :: myCInt       ! { dg-warning "is for type REAL" }
+  integer(c_double), bind(c) :: myCInt2 ! { dg-warning "is for type REAL" }
 
   integer, parameter :: myI = c_int
-  real(myI) :: myReal             ! { dg-error "is for type INTEGER" }
-  real(myI), bind(c) :: myCFloat2 ! { dg-error "is for type INTEGER" }
+  real(myI) :: myReal             ! { dg-warning "is for type INTEGER" }
+  real(myI), bind(c) :: myCFloat2 ! { dg-warning "is for type INTEGER" }
   real(4), bind(c) :: myFloat     ! { dg-warning "may not be a C interoperable" }
 end module c_kind_tests_2
Index: gcc/testsuite/gfortran.dg/interop_params.f03
===================================================================
--- gcc/testsuite/gfortran.dg/interop_params.f03	(revision 147433)
+++ gcc/testsuite/gfortran.dg/interop_params.f03	(working copy)
@@ -14,7 +14,7 @@ contains
   end subroutine test_0
 
   subroutine test_1(my_f90_real) bind(c)
-    real(c_int), value :: my_f90_real    ! { dg-error "is for type INTEGER" }
+    real(c_int), value :: my_f90_real    ! { dg-warning "is for type INTEGER" }
   end subroutine test_1
 
   subroutine test_2(my_type) bind(c) ! { dg-error "is not C interoperable" }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]