Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

type to class conversion in call with optional arguments

$
0
0

Out of curiosity, does anybody know whether the following code is standard conform or not. This was due to a minor oversight, but took a while to figure out, as the ifort compiler does not give any meaningful error messages but crashs with a segfault, whereas gfortran just works.
The problem is that in sub1, argument p is declared with type(t) and in sub2 it is declared with class(t).

program optional

type :: t
integer, pointer :: x
end type t

type(t) :: a
integer, pointer :: y

allocate(a%x, source=1)
call sub1(a, c=y)

contains

subroutine sub1(a, p, c)
class(t), intent(in) :: a
type(t), optional, intent(out) :: p
integer, pointer, optional, intent(out) :: c
call sub2(a, p, c)
end subroutine sub1

subroutine sub2(a, p, c)
class(t), target, intent(in) :: a
class(t), optional, intent(out) :: p
integer, pointer, optional, intent(out) :: c
if (present(p)) then
p%x => a%x
else
c => a%x
end if
end subroutine sub2

end program optional


Viewing all articles
Browse latest Browse all 2746

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>