- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code (line 27) gives error #9140 (The allocatable result of a function reference may not be argument associated with an allocatable dummy argument) in IFX2024.0.0 and IFORT2021.11.0 but didn't in previous IFORT versions. OK I guess the code is illegal and it got smarter. It is easy to workaround but a but more verbose on the coding.
I can see that "printdata" could not change the allocation status of the input which is the result of the the array that is created by the function "setdata" , however as it is intent(in) such change is not possible. Is this a correct/necessary constraint when intent(in) applies?
A Fortran standards query really I suppose.
module m_alloc_arg_err
implicit none(type, external)
contains
function setdata()
integer, allocatable :: setdata(:)
setdata = [ 1, 2, 3 ]
end function setdata
subroutine printdata( idat )
integer,intent(in), allocatable, optional :: idat(:)
if ( present(idat) ) then
if ( allocated( idat ) ) then
print *, idat
else
print *,'present not alloc'
endif
else
print *,'not present'
endif
end subroutine printdata
end module m_alloc_arg_err
program alloc_arg_err
use m_alloc_arg_err
implicit none(type, external)
integer :: i
integer, allocatable :: j(:)
print *, 'Hello World'
!call printdata( setdata() ) ! line give error #9140 but worked in older versions of the compiler
! error #9140: The allocatable result of a function reference may not be argument associated with an allocatable dummy argument. [SETDATA]
call printdata() ! usage case 1 - not present
call printdata( J ) ! usage case 2 - present notallocated
j = [4,5,6]
call printdata( J ) ! usage case 3 - present and allocated
j = setdata()
call printdata( J ) ! workaround case but needs demands more lines of code
read(*,*) I
end program alloc_arg_err
! ****expected output****
! Hello World
! not present
! present not alloc
! 4 5 6
! 1 2 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Yes that reproducer in essence mimics my example. And yes having read up it does appear to be non-conforming.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
same result on VS 2022 Preview, latest oneapi, even though I now feel like a thief
on 64 bit release 64 bit debug 32 bit both ways
ifx - no problems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What about:
function setdata() result(ret)
integer, allocatable :: ret(:)
ret = [ 1, 2, 3 ]
end function setdata
I've had some quirky issues when using the function name as the result, but where explicit result resolved the issue.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim:
The answer remaineth the sameth.
it matcheth the answer provided by the author. So I am lost.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a change in the compiler. I submitted a bug based on this report earlier this year. And it's fixed in the available, but not quite announced, ifx and ifort compilers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Yes that reproducer in essence mimics my example. And yes having read up it does appear to be non-conforming.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your new IFX compiler still throws the error, under 22 and 19 with IFX and IFORT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do I need to give you anything else, I give you the full solution as it is small.
I tried it on all Flavours and for 22 and 19; it did not compile.
I am running IFX on all versions and it is sweet, not sweaty, just sweet.
I wish to apologize for pushing your Ron into Greek stories, soon he will be as bad as me.
As mum said often, Son you are trying.
Or as my sophomore high school science teacher said to my mother and she told me, He thinks you are a pain in the butt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page