Hello,
the program below causes an ICE in the PGI Fortran compiler (CE, 17.10). If I comment out the “program … end program” part, then the compiler gives a message about severe errors, but finishes normally.
The thing is not that the program is syntactically incorrect, but that the compiler crashes.
I am not sure it can be reduced even further.
Kind regards,
Arjen
! vectorspace.f90 --
! Define a module for dealing with vector spaces in an abstract sense
!
! The basic data type is an abstract vector, with the following
! operations:
! "+" - to add two vectors to get a new vector
! "*" - to multiply a vector with a scalar
! We can use an array of vectors as a collection: the operation ".in."
! determines if a given vector is in that collection.
!
! Note:
! This causes an ICE in the PGI Fortran compiler
!
module vectorspaces
implicit none
type, abstract :: vector
contains
private
procedure(addition), deferred :: add
end type vector
abstract interface
function addition( a, b )
import :: vector
class(vector), intent(in) :: a, b
class(vector), allocatable :: addition
end function addition
end interface
end module vectorspaces
!
! Test this with an actual implementation
!
module vectors_3d
use vectorspaces
type, extends(vector) :: vector_3d
real, dimension(3) :: coords
contains
procedure :: add => add_3d
end type
contains
function add_3d( a, b )
class(vector), intent(in) :: a
class(vector_3d), intent(in) :: b
class(vector_3d), allocatable :: add_3d
allocate( add_3d )
add_3d%coords = a%coords + b%coords
end function add_3d
end module vectors_3d
! Test program for the vector space modules
!
! Note:
! To keep the program small, there is no facility to manipulate a collection
! of vectors, but you could add that too.
!
program test_space
use vectors_3d
implicit none
type(vector_3d) :: a, b, c
type(vector_3d), dimension(10) :: vectors
a = vector_3d( [1.0, 1.0, 1.0] )
b = vector_3d( [2.0, 2.0, 2.0] )
c = a + b
end program test_space