public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/49509] New: cannot promote types for arguments passed by value
@ 2011-06-22 22:10 stevenj at alum dot mit.edu
  2011-06-23  2:11 ` [Bug fortran/49509] " kargl at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: stevenj at alum dot mit.edu @ 2011-06-22 22:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49509

           Summary: cannot promote types for arguments passed by value
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: stevenj@alum.mit.edu


Compile the following test program gfortran, which is a toy example of
iso_c_binding that calls malloc(3).

  program bug

  use, intrinsic :: iso_c_binding
  implicit none
  interface
     type(C_PTR) function malloc(n) bind(C, name='malloc')
       import
       integer(C_SIZE_T), value :: n
     end function malloc
  end interface

  integer, parameter :: n = 3
  integer(C_SIZE_T) sz
  type(C_PTR) p
  p = malloc(n)  ! compiler error, cannot promote argument passed by value
  sz = n         ! ... whereas assignment succeeds
  p = malloc(sz)

  end program bug

I obtain the following error:

  promote.f03:15.13:

    p = malloc(n) ! compiler error, cannot promote argument type
               1
  Error: Type mismatch in argument 'n' at (1); passed INTEGER(4) to INTEGER(8)

(Similarly with older versions of gcc.)  Note that "n" is passed by value, so
my understanding is that this should act much like the assignment sz = n (which
succeeds): gfortran should automatically promote n to a size_t, like any other
assignment of a narrower type to a wider type.

Please consider applying the same type-promotion rules that are used for
assignments to passing arguments by value.  (I don't have the Fortran 2003
standard handy, but it is hard to believe that the two situations should be
treated differently.)


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-08-06 21:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-22 22:10 [Bug fortran/49509] New: cannot promote types for arguments passed by value stevenj at alum dot mit.edu
2011-06-23  2:11 ` [Bug fortran/49509] " kargl at gcc dot gnu.org
2011-06-23  2:55 ` stevenj at alum dot mit.edu
2011-06-23  3:01 ` stevenj at alum dot mit.edu
2011-06-23  3:23 ` stevenj at alum dot mit.edu
2011-06-23  4:02 ` sgk at troutmask dot apl.washington.edu
2011-06-23  4:02 ` sgk at troutmask dot apl.washington.edu
2011-06-23  4:14 ` sgk at troutmask dot apl.washington.edu
2011-06-23  4:23 ` sgk at troutmask dot apl.washington.edu
2011-06-23 16:07 ` burnus at gcc dot gnu.org
2011-08-06 21:09 ` tkoenig at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).