Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28701 Discussions

error #9140: The allocatable result of a function reference may not be argument associated with an a

andrew_4619
Honored Contributor III
1,201 Views

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

 

 

0 Kudos
1 Solution
andrew_4619
Honored Contributor III
1,088 Views

Thanks, Yes that reproducer in essence mimics my example. And yes having read up it does appear to be non-conforming.

View solution in original post

0 Kudos
10 Replies
JohnNichols
Valued Contributor III
1,188 Views

Screenshot 2023-11-19 132020.png

 

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. 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,164 Views

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

0 Kudos
JohnNichols
Valued Contributor III
1,145 Views

Jim:

The answer remaineth the sameth. 

Screenshot 2023-11-19 182034.png

it matcheth the answer provided by the author.  So I am lost.  

0 Kudos
andrew_4619
Honored Contributor III
1,125 Views
It would, the line that causes it to fail to compile is commented out.
0 Kudos
Barbara_P_Intel
Employee
1,091 Views

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.

andrew_4619
Honored Contributor III
1,089 Views

Thanks, Yes that reproducer in essence mimics my example. And yes having read up it does appear to be non-conforming.

0 Kudos
JohnNichols
Valued Contributor III
1,072 Views

Screenshot 2023-11-20 143441.png

Your new IFX compiler still throws the error, under 22 and 19 with IFX and IFORT. 

0 Kudos
Barbara_P_Intel
Employee
1,066 Views

@JohnNichols, thanks for verifying!  We WANT the error. It was missing in earlier releases.

 

0 Kudos
JohnNichols
Valued Contributor III
1,062 Views

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.  

 

0 Kudos
Barbara_P_Intel
Employee
1,037 Views

Thank you, @JohnNichols. The compiler is giving a correct error message.

 

0 Kudos
Reply