• Issue with parameterized type in gfortran, or is it a language issue?

    From Bastiaan Braams@21:1/5 to All on Mon Nov 8 09:18:58 2021
    The following code fails to compile under gfortran 10.3.1, and I don't have convenient access to another compiler. Is it a gfortran issue or am I missing something in the language specification?
    program test
    type mytype (n)
    integer, len :: n
    end type mytype
    contains
    subroutine sub (u, v)
    type (mytype(n=*)), intent (out) :: u
    integer, intent (out) :: v(0:)
    ! gfortran does not accept the following declaration for x
    ! "Dummy argument ‘u’ at (1) cannot be INTENT(OUT)"
    integer :: x(u%n), y(size(v))
    end subroutine sub
    end program test
    I've included a declaration involving size(v), which is accepted fine, and I had
    expected the declaration that uses u%n to be accepted as well. (Under circumstances the call to subroutine sub might generate a run-time error,
    but I am getting a compile-time error.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From pehache@21:1/5 to All on Mon Nov 8 19:24:37 2021
    Le 08/11/2021 à 18:18, Bastiaan Braams a écrit :
    program test
    type mytype (n)
    integer, len :: n
    end type mytype
    contains
    subroutine sub (u, v)
    type (mytype(n=*)), intent (out) :: u
    integer, intent (out) :: v(0:)
    ! gfortran does not accept the following declaration for x
    ! "Dummy argument ‘u’ at (1) cannot be INTENT(OUT)"
    integer :: x(u%n), y(size(v))
    end subroutine sub
    end program test

    declaring u as intent(out) tells the compiler that it could
    uninitialised upon entering the routine, thus that the declaration
    x(u%n) could not be "resolved".

    Using the intent() specifier has also the purpose enabling compile-time
    checks.

    --
    "...sois ouvert aux idées des autres pour peu qu'elles aillent dans le
    même sens que les tiennes.", ST sur fr.bio.medecine

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bastiaan Braams@21:1/5 to pehache on Mon Nov 8 12:48:02 2021
    On Monday, November 8, 2021 at 7:24:42 PM UTC+1, pehache wrote:
    Le 08/11/2021 à 18:18, Bastiaan Braams a écrit :
    program test
    type mytype (n)
    integer, len :: n
    end type mytype
    contains
    subroutine sub (u, v)
    type (mytype(n=*)), intent (out) :: u
    integer, intent (out) :: v(0:)
    ! gfortran does not accept the following declaration for x
    ! "Dummy argument ‘u’ at (1) cannot be INTENT(OUT)"
    integer :: x(u%n), y(size(v))
    end subroutine sub
    end program test
    declaring u as intent(out) tells the compiler that it could
    uninitialised upon entering the routine, thus that the declaration
    x(u%n) could not be "resolved".

    Using the intent() specifier has also the purpose enabling compile-time checks.

    --
    "...sois ouvert aux idées des autres pour peu qu'elles aillent dans le même sens que les tiennes.", ST sur fr.bio.medecine

    But u%n in the posted code is a type parameter inquiry, it is not a structure component selector, and it may appear even if u is undefined. The way I read Sec 7.4.2 (specification expressions) in the Fortran 2003 handbook [1], u%n is a valid
    specification expression just like size(v) is a valid specification expression. (Both u and v have intent (out).)

    [1] Adams, Jeanne C., Walter S. Brainerd, Richard A. Hendrickson, Richard E. Maine, Jeanne T. Martin, and Brian T. Smith. The Fortran 2003 handbook: the complete syntax, features and procedures. Springer, 2008.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From FortranFan@21:1/5 to bjbr...@gmail.com on Mon Nov 8 13:21:45 2021
    On Monday, November 8, 2021 at 12:19:00 PM UTC-5, bjbr...@gmail.com wrote:

    The following code fails to compile under gfortran 10.3.1, and I don't have convenient access to another compiler. Is it a gfortran issue or am I missing something in the language specification?
    ..

    For whatever it's worth, I think it is a gfortran issue. Please see the thread link, there are many outstanding issues with gfortran when it comes to parameterized derived types:
    https://groups.google.com/g/comp.lang.fortran/c/NDE6JKTFbNU/m/ebr9ocS9AAAJ

    Re: "I don't have convenient access to another compiler," a question: will it be possible for you to try Intel Fortran compiler? It is now available for users without needing to purchase a license; users can procure subscription for support services if
    they so choose. https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html

    You will find Intel Fortran compiler to support parameterized derived types.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)