From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10091 invoked by alias); 22 Jun 2011 22:10:00 -0000 Received: (qmail 10079 invoked by uid 22791); 22 Jun 2011 22:09:59 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Jun 2011 22:09:46 +0000 From: "stevenj at alum dot mit.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/49509] New: cannot promote types for arguments passed by value X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: stevenj at alum dot mit.edu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Wed, 22 Jun 2011 22:10:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg02026.txt.bz2 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.)