http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46990
Summary: [OOP] gfortran rejects passing a CLASS variable to
TYPE
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: fortran
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
In the following program a polymorphic dummy is passed as actual argument to a
non-polymorphic dummy of the declared type.
The program compiles with the ifort 11.1 and nagf95 5.1, but gfortran rejects
it with:
call two(x)
1
Error: Type mismatch in argument 'x' at (1); passed CLASS(t) to TYPE(t)
Both compiler reject passing a CLASS(t2) variable to TYPE(t) or CLASS(t) to
TYPE(t2). (Where "t2" extends type "t".)
* * *
>From the standard.
"The dummy argument shall be type compatible with the actual argument. If the
actual argument is a polymorphic coindexed object, the dummy argument shall not
be polymorphic." (F2008, 12.5.2.4)
"A nonpolymorphic entity is type compatible only with entities of the same
declared type." (4.3.1.3)
Thus, the dummy argument (a nonpolymorphic entitiy) is type compatible with
entities (i.e. actual actual arguments) of the same declared type.
* * *
module m
type t
integer :: i
end type t
contains
subroutine one(x)
class(t) :: x
call two(x)
end subroutine one
subroutine two(x)
type(t) :: x
end subroutine two
end module m