This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, Fortran] PR 36947/40039: Better error messages for dummy procedures and check for OPTIONAL
- From: Tobias Burnus <burnus at net-b dot de>
- To: Janus Weil <janus at gcc dot gnu dot org>, fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 25 May 2009 12:16:12 +0200
- Subject: Re: [Patch, Fortran] PR 36947/40039: Better error messages for dummy procedures and check for OPTIONAL
Janus,
> this follow-up adds a check for OPTIONAL and improves the
> error messages
Thanks for improving the error messages - they are very useful!
Thanks also for the OPTIONAL check.
I will look though the patch itself later (ditto for your other
patch).
> "If the interface of the dummy argument is explicit, the
> characteristics listed in 12.2 shall be the same for the
> associated actual argument and the corresponding dummy argument, ..."
I think passing an actual argument with an implicit interface to
an explicit-interface dummy is also allowed. If the explicit
argument were required, the standard had written it explicitly.
(If an explicit interface is required (allocatable, optional, assumed-shape
argument etc.; both dummy/actual and proc-pointer/proc-target have to
have an explicit interface. That could actually be checked for :-)
It just states that they need to match, which means that it might not be
checkable if the procedure definition is not in host/use-associated scope
(or has an INTERFACE, which in turn shall match the actually existing
procedure).
* * *
I think some other checks should still be added, e.g.
a) PUREness check (see example below); passing/assigning
a pure to a non-pure dummy/proc-pointer is OK; doing vice versa
is not.
See "12.4.1.3" (dummy-actual arguments)
"If the interface of the dummy argument is explicit,
the characteristics listed in 12.2 shall be the same for the
associated actual argument and the corresponding dummy argument,
except that a pure actual argument may be associated with a dummy
argument that is not pure and an elemental intrinsic actual
procedure may be associated with a dummy procedure (which is
prohibited from being elemental)."
And also "7.4.2.2" (proc-pointer assignment):
"If proc-pointer-object has an explicit interface, its
characteristics shall be the same as proc-target except that
proc-target may be pure even if proc-pointer-object is not pure
and proc-target may be an elemental intrinsic procedure even
if proc-pointer-object is not elemental."
b) Similarly for ELEMENTAL. For proc-pointer assignments, use the
first example with PURE changed to ELEMENTAL. That non-intrinsic
elementals are not allowed as actual argument, is already checked
for (cf. C1228). Except of the remark in parentheses I could not
find in F2003/F2008 anything which prohibits ELEMENTAL for the
dummy argument; however, the parentheses is normative. Maybe one
should re-check the standard before adding an error check (see
example below).
c) One needs to go recursively over the arguments as the second
example below shows.
Tobias
PROGRAM PURENESS
implicit none
interface
subroutine one(a,b,c,d,e,f,g,h,i)
implicit none
integer,intent(in) :: a,b,c,d,e,f,g,h,i
end subroutine one
pure subroutine two(a,b,c,d,e,f,g,h,i)
implicit none
integer,intent(in) :: a,b,c,d,e,f,g,h,i
end subroutine two
end interface
procedure(two), pointer :: ptr
ptr => one ! Invalid: (pure) => (unpure)
end program pureness
program RecursiveInterface
interface
subroutine a(x)
real :: x
end subroutine a
subroutine b(a)
integer :: a
end subroutine b
subroutine c(f)
procedure(a) :: f
end subroutine c
subroutine d(f)
procedure(b) :: f
end subroutine d
subroutine e(f)
procedure(c) :: f
end subroutine e
end interface
call e(d) ! Argument (dummy subroutine) d has an integer argument
! but e's f expects a real argument
end program RecursiveInterface
interface
elemental subroutine a() ! Expected: Warning: ELEMENTAL procedure
! without arguments
! (Having ELEMENTAL does not make much sense without arguments, but
! it is valid)
end subroutine a
subroutine sub(f)
interface
elemental subroutine f(a)
integer,intent(IN) :: a
end subroutine f
end interface
! Invalid per 12.4.1.3?
! "an elemental intrinsic actual procedure may be associated with
! a dummy procedure (which is prohibited from being elemental)."
! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
! Todo: Find it elsewhere in the standard - or in the corrigenda;
! other compilers accept it. However, the part above is normative
end subroutine sub
end interface
end program elementalCheck