[J3] Question about interface matchine
Mark LeAir
mleair at nvidia.com
Wed Jan 27 23:57:00 UTC 2021
Just to clarify, my section numbers came from the Fortran 2018 spec. 😊
-----Original Message-----
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Mark LeAir via J3
Sent: Wednesday, January 27, 2021 3:54 PM
To: Brad Richardson <everythingfunctional at protonmail.com>; General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Mark LeAir <mleair at nvidia.com>
Subject: Re: [J3] Question about interface matchine
External email: Use caution opening links or attachments
It is legal Fortran based on section "15.5.2.4 Ordinary dummy variables", paragraph 3 which states in part:
"The dummy argument shall be type compatible with the actual argument..."
Section "7.3.2.3 CLASS type specifier", paragraph 5, second sentence, states:
" A polymorphic entity that is not an unlimited polymorphic entity is type compatible with entities of the same declared type or any of its extensions...."
And as we know both bar and dummy argument rhs have the same declared type (foo_t).
-Mark
-----Original Message-----
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Brad Richardson via J3
Sent: Wednesday, January 27, 2021 2:24 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Brad Richardson <everythingfunctional at protonmail.com>
Subject: [J3] Question about interface matchine
External email: Use caution opening links or attachments
Hi all,
Could someone please tell me whether the following code is standards conformant, and if so why? I contend that both the declared and dynamic type of bar do not match the interface and thus the code should not compile or execute without error. But gfortran, intel, and nag all compile and execute this code without complaint. Is there something about interface matching and argument types that I’m not understanding?
module foo_m
implicit none
type :: foo_t
contains
procedure :: copy_into
end type
type, extends(foo_t) :: bar_t
end type
contains
subroutine copy_into(self, rhs)
class(foo_t), intent(inout) :: self
type(foo_t), intent(inout) :: rhs
end subroutine
end module
program main
use foo_m, only: foo_t, bar_t
implicit none
type(foo_t) :: foo
class(foo_t), allocatable :: bar
bar = bar_t()
call foo%copy_into(bar)
end program
Thanks,
Brad Richardson
More information about the J3
mailing list