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

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

andrew_4619
Contributeur émérite III
1 919 Visites

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 Compliments
1 Solution
andrew_4619
Contributeur émérite III
1 806 Visites

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

Voir la solution dans l'envoi d'origine

0 Compliments
10 Réponses
JohnNichols
Précieux contributeur III
1 906 Visites

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 Compliments
jimdempseyatthecove
Contributeur émérite III
1 882 Visites

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 Compliments
JohnNichols
Précieux contributeur III
1 863 Visites

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 Compliments
andrew_4619
Contributeur émérite III
1 843 Visites
It would, the line that causes it to fail to compile is commented out.
0 Compliments
Barbara_P_Intel
Employé
1 809 Visites

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
Contributeur émérite III
1 807 Visites

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

0 Compliments
JohnNichols
Précieux contributeur III
1 790 Visites

Screenshot 2023-11-20 143441.png

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

0 Compliments
Barbara_P_Intel
Employé
1 784 Visites

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

 

0 Compliments
JohnNichols
Précieux contributeur III
1 780 Visites

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 Compliments
Barbara_P_Intel
Employé
1 755 Visites

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

 

0 Compliments
Répondre