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

Structure constructor when components belong to an array

$
0
0

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?





 







 


Viewing all articles
Browse latest Browse all 2583

Trending Articles



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