On Friday, November 24, 2017 at 11:41:23 AM UTC-5, Thomas Jahns wrote:
> ..
>
> Is there a known work-around (e.g. some compiler option)? Does the observed
> behaviour conform to any release of the Fortran standard? ..
To me, it looks like a bug in the Intel Fortran 18.0 compiler. And it is worthy of a support request at the Intel Online Service Center (OSC), at least for you to learn what Intel's Fortran team thinks of the issue.
https://supporttickets.intel.com/?lang=en-US
Re: a work-around, one option is to treat variables with the POINTER attribute in Fortran as entities that only *point* to some explicit targets with ALLOCATABLE attribute as opposed to anonymous targets which come into play in the code in the original post. It can make codes a lot safer and cleaner with far fewer worries about memory leaks and also be easier to understand and maintain:
module bar
implicit none
private
integer, allocatable, target, save :: m_dat(:)
public :: baz
contains
subroutine baz( p )
integer, pointer, intent(inout) :: p(:)
! Any checks elided
p => null()
if ( .not. allocated(m_dat) ) then
allocate( m_dat(5) )
end if
m_dat = 23
p => m_dat
return
end subroutine
end module
program foo
use, intrinsic :: iso_fortran_env, only : compiler_version
use bar, only: baz
implicit none
integer, allocatable, target :: q(:)
integer, pointer :: p(:)
print *, "Compiler version: ", compiler_version()
allocate( q(5) )
p => q
q = 42
write (0, '(a,10(" ",i0))') 'p = ', p
write (0, '(a,10(" ",i0))') 'q = ', q
call baz(p)
write (0, '(a,10(" ",i0))') 'p = ', p
write (0, '(a,10(" ",i0))') 'q = ', q
p => null()
stop
end program foo
Upon execution using Intel Fortran 18.0 compiler update 1,
Compiler version:
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.1.156 Build 20171018
- hide quoted text -