gfortran currently treats C_LOC as suitable for initialization expressions;
however, it does not seem to be valid in either Fortran 2003 nor Fortran 2008. 

use iso_c_binding
implicit none
integer, target :: a
type t
  type(c_ptr) :: ptr = c_loc(a)
end type t
type(c_ptr) :: ptr2 = c_loc(a)
end


F2003 has:

"7.1.7 Initialization expression"
"It is an expression in which each operation is intrinsic, and each primary is
[...] (8) A specification inquiry [...]"

Similarly in F2008's "7.1.12 Constant expression".

The definition for "specification inquiry" is in Fortran 2008 (7.1.11
Specification expression):
"A specication inquiry is a reference to
(1) an intrinsic inquiry function,
[...]
(4) the function C_SIZEOF from the intrinsic module ISO C BINDING (15.2.3.7)"

Fortran 2003 is even more restrictive (cf. 7.1.6 Specification expression),
which rules out that C_LOC can be used.

In principle, I would claim that C_LOC matches "(1) an intrinsic inquiry
function"; however, as (3), (4) and (5) explicitly list suitable functions from
the modules, I think one has to rule that it is also invalid in F2008 and not
only in F2003.


-- 
           Summary: Invalidly accepts C_LOC in init expressions
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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

Reply via email to