Bug 39189 - Improvement in handling COMMON'ed pointers to allocatable arrays
Summary: Improvement in handling COMMON'ed pointers to allocatable arrays
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.3
: P5 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-14 02:04 UTC by Pavel Boldin
Modified: 2009-02-19 05:40 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Boldin 2009-02-14 02:04:04 UTC
When using perverted technique like:

SUBROUTINE A
INTEGER, ALLOCATABLE, DIMENSION(:), TARGET :: ARRAY
INTEGER, POINTER, DIMENSION(:) :: ARRAY_PTR
COMMON /AP/ ARRAY_PTR !for later use in another sub

ALLOCATE(ARRAY(10))
ARRAY = 10
ARRAY_PTR => ARRAY

END SUBROUTINE A

SUBROUTINE B
INTEGER, POINTER, DIMENSION(:) :: ARRAY_PTR
COMMON /AP/ ARRAY_PTR !for later use in another sub

print *, ARRAY_PTR(1)
END SUBROUTINE


one can figure out, that ARRAY will be free'd after finishing subroutine A (because it was not SAVE'd). But gfortran still allows to play such a trick.

I think it would be nice to see warning in such case (pointing to data that will be lost after this scope)
Comment 1 kargls 2009-02-14 16:00:18 UTC
I'm inclined to think that this should be closed with WONTFIX.

Deallocation of an allocated array when a subprogram returns
is a fundamental concept of Fortran.  A user should know what
to expect and code accordingly.

I'll let one of the other gfortran contributors make a final
determination of the merits of a warning.
Comment 2 Paul Thomas 2009-02-19 05:40:44 UTC
I agree with Steve and have marked this as WONTFIX.

You should use another pointer and allocate to that if you want to avoid the automatic deallocation on leaving scope.

Paul