Structure constructor when components belong to an array

Structure constructor when components belong to an array

Hi,

I get an error when trying to compile the following code:

module mod1

    implicit none
    private
    save

    type, public :: t1
        real :: a1 = 0
        real :: b1 = 0
    end type

    type, extends(t1), public :: t2
        real :: a2 = 0
        real :: b2 = 0
    end type

    type, extends(t2), public :: t3
        real :: a3 = 0
        real :: b3 = 0
    end type

end module mod1

module mod2

    use mod1

    implicit none
    private
    save

    real, allocatable :: x(:,:,:)

    public setting
    public printing
    public printing2

contains
    !--------------------------------------------------------------------------
    subroutine setting()
        integer :: i, istat

        deallocate (x, STAT = istat)
        allocate (x(2,2,2))
        x = RESHAPE([(REAL(i), i = 1, SIZE(x))], SHAPE(x))
    end subroutine

    !--------------------------------------------------------------------------
    subroutine printing()
        if (.NOT. ALLOCATED(x)) return
        !***ifort doesn't like this one:
        print *, t3(x(1,1,1), x(2,1,1), x(1,2,1), x(2,2,1), x(1,1,2), x(2,1,2))
    end subroutine

    !--------------------------------------------------------------------------
    subroutine printing2()
        real :: a1, b1, a2, b2, a3, b3

        if (.NOT. ALLOCATED(x)) return
        a1 = x(1,1,1)
        b1 = x(2,1,1)
        a2 = x(1,2,1)
        b2 = x(2,2,1)
        a3 = x(1,1,2)
        b3 = x(2,1,2)

        !***but it likes this one:
        print *, t3(a1, b1, a2, b2, a3, b3)
    end subroutine
end module

use mod2

implicit none

call setting()
call printing()
call printing2()

end

The printing2() subroutine is equivalent to the printing() subroutine, only using scalars instead of array entries, so commenting line 53 makes the error go away.

It seems to me like yet another structure constructor plus arrays bug ---or am I missing something in regards to single inheritance? Or something else?

 

 

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

This does appear to be a defect with ifort. I reported this to Development (see internal tracking id below). I also found gfortran accepts and produces identical results for both forms.
(Internal tracking id: DPD200255191)

Leave a Comment

Please sign in to add a comment. Not a member? Join today