This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[PATCH,fortran] Relax restrictions on KIND in SELECT CASE constructs


Consider this program posted by James Van Buskirk in c.l.f.
gfortran currently issues an error because the KIND of 7 and
200 do not match the KIND of x.

program case_ex
   implicit none
   integer, parameter :: ik1 = selected_int_kind(2)
   integer(ik1) x
   integer io

   write(*,'(a)',advance='no',iostat=io) ' Enter the value of x:> '
   read(*,*) x
   if(io /= 0) x = 0
   select case(x)
   case(7)
      write(*,'(a)') ' Sorry, bad guess.'
   case(200)
      write(*,'(a)') ' You win the prize!'
   case default
      write(*,'(a)') ' You aren''t even trying.'
   end select
end program case_ex

The relevant constraint from the Fortran standard is 

  C805 (R808) For a given case-construct, each case-value shall be of
  the same type as case-expr.  For character type, length differences
  are allowed, but the kind type parameters shall be the same.  */

and we note no such requirement of the KIND for INTEGER and LOGICAL
variables must match.

The attached patch relaxes gfortran's restriction to match C805.

2004-12-17  Steven G. Kargl  <kargls@comcast.net>

     * resolve.c (validate_case_label_expr): Fix handling of mismatched KINDs.

-- 
Steve

Attachment: resolve.c.diff
Description: Text document


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