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]

Re: test for allocatable function (f95 extension)


Uttam Pawar wrote:
$ cat test.f90 program no_leak
real, dimension(100) :: x, y
y(:size(compact(x))) = compact(x)**2
contains
function compact(x)
real,allocatable,dimension(:) :: compact
real,dimension(:),intent(in) :: x
integer :: n
allocate(compact(n))
end function compact
end


$ test.f90
gfortran test.f90

In file test.f90:6

             real,allocatable,dimension(:) :: compact
                                                    1
Error: ALLOCATABLE attribute conflicts with FUNCTION attribute at (1)

Fortran 95 Draft standard, section 5.2.6: "Constraint: The array-name [in an ALLOCATABLE statement] shall not be a ... function result."


I can't find where it directly gives the same constraint for ALLOCATABLE as an attribute rather than in a statement of its own, but the first paragraph of 5.2 says, regarding attribute specification statements: "The combination of attributes that may be specified for a particular entity is subject to the same restrictions as for type declaration statements regardless of the method of specification," which I would infer is intended to mean that this constraint applies to the case you illustrate as well.

This is, I believe, something added in one of the F95 TRs and in F2003.

- Brooks


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