Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

74 views
Skip to first unread message

Bastiaan Braams

unread,
Nov 8, 2021, 12:19:00 PM11/8/21
to
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.)

pehache

unread,
Nov 8, 2021, 1:24:42 PM11/8/21
to
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

Bastiaan Braams

unread,
Nov 8, 2021, 3:48:04 PM11/8/21
to
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.

FortranFan

unread,
Nov 8, 2021, 4:21:47 PM11/8/21
to
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.
0 new messages