[Bug fortran/41724] New: PUREness/ELEMENTAL check missing for ACTUAL/DUMMY conformance
burnus at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Fri Oct 16 08:26:00 GMT 2009
One again a bug report based on the famous compiler stress tests of James Van
Buskirk
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/da1feef5e8c9ed9a
Pre-remark: After writing this PR, I realized the following parenthesis:
"with a dummy procedure (which is prohibited from being elemental)"
I failed to quickly find the restriction elsewhere - but the text is normative.
Thus also PROGRAM C should be invalid. One should re-check and consider to add
a check whether a DUMMY argument is also ELEMENTAL and reject it then.
Program A (Validly rejected by gfortran; but should accept as extension?)
gfortran rejects the program with
Error: ELEMENTAL non-INTRINSIC procedure 'my_dcos' is not allowed as an actual
argument at (1)
That's in line with Fortran 95, "12.4 Procedure reference":
"Constraint: A non-intrinsic elemental procedure shall not be used as an
actual argument."
and Fortran 2003 has:
"C1228 (R1221) A nonintrinsic elemental procedure shall not be used as an
actual argument."
and Fortran 2008:
"C1233 (R1223) A nonintrinsic elemental procedure shall not be used as an
actual argument."
Interestingly, the program is accepted by (!) NAG f95 (with "extension"
warning) and ifort (with warning using -stand f03). (sunf95, openf95, g95 and
gfortran unconditionally reject it.)
PROGRAM B - gfortran accepts invalid
The program is accepted by gfortran, sunf95, and (!) NAG f95, but rejected by
ifort and g95 with the error:
Error: Dummy procedure 'my_dcos' at (1) must be PURE
error #7892: Procedure argument must be PURE [MY_DCOS]
error #7050: The PURE attribute of the associated actual procedure differs
from the
PURE attribute of the dummy procedure. [MY_DCOS]
error #7849: The ELEMENTAL attribute of the associated actual procedure
differs from the
ELEMENTAL attribute of the dummy procedure. [MY_DCOS]
We recall (see below): The dummy argument is ELEMENTAL, but the actual argument
is a simple function - neither PURE nor ELEMENTAL.
gfortran actually misses a check as Fortran 2003 states (12.4.1.3 Actual
arguments associated with dummy procedure entities):
"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)."
(Side remark: In Fortran 2008 IMPURE ELEMENTAL procedures are allowed; without
IMPURE - and thus always in F95/F2003 - ELEMENTAL implies PURE. - But that does
not help here)
PROGRAM C - looks to be valid [or not?] and is accepted
Calling DCOS as actual argument is standard conform (listed as specific
function and does not have a "*" before the entry). (gfortran accepts it,
ifort rejects it.)
[But see note above regarding ELEMENTAL dummies]
===================== PROGRAM A ======================
module funcs
implicit none
integer, parameter :: dp = kind(1.0d0)
contains
ELEMENTAL function my_dcos(x)
integer, parameter :: dp = kind(1.0d0)
real(dp), intent(in) :: x
real(dp) :: my_dcos
my_dcos = cos(x)
end function
subroutine test(fun)
interface
ELEMENTAL function fun(x)
import
implicit none
real(dp), intent(in) :: x
real(dp) fun
end function fun
end interface
real(dp) x(3)
x = [1,2,3]
write(*,*) fun(x)
end subroutine test
end module funcs
program start
use funcs
implicit none
call test(my_dcos)
end program start
===================== PROGRAM B ======================
module funcs
implicit none
integer, parameter :: dp = kind(1.0d0)
contains
function my_dcos(x) ! Not elemental
integer, parameter :: dp = kind(1.0d0)
real(dp), intent(in) :: x
real(dp) :: my_dcos
my_dcos = cos(x)
end function
subroutine test(fun)
interface
ELEMENTAL function fun(x)
import
implicit none
real(dp), intent(in) :: x
real(dp) fun
end function fun
end interface
real(dp) x(3)
x = [1,2,3]
write(*,*) fun(x)
end subroutine test
end module funcs
program start
use funcs
implicit none
call test(my_dcos)
end program start
===================== PROGRAM C ======================
module funcs
implicit none
integer, parameter :: dp = kind(1.0d0)
contains
subroutine test(fun)
interface
ELEMENTAL function fun(x)
import
implicit none
real(dp), intent(in) :: x
real(dp) fun
end function fun
end interface
real(dp) x(3)
x = [1,2,3]
write(*,*) fun(x)
end subroutine test
end module funcs
program start
use funcs
implicit none
intrinsic dcos
call test(dcos)
end program start
--
Summary: PUREness/ELEMENTAL check missing for ACTUAL/DUMMY
conformance
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: burnus at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41724
More information about the Gcc-bugs
mailing list