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

Problem with structure constructor

$
0
0

ifort produces an error compiling the following code:

module m
 implicit none

 type, abstract :: c_a
 end type c_a

 type, extends(c_a), abstract :: c_b
 !type, abstract :: c_b ! removing the ancestor solves the problem
  real, pointer :: x => null()
 end type c_b

 type, extends(c_b) :: t_c
  logical :: l
 end type t_c

end module m

program p
 use m
 implicit none

 real, target :: r
 ! renaming/removing the variable x solves the problem
 type(t_c),  parameter   :: x = t_c( l=.false. )
 class(c_b), allocatable :: y

  allocate( y , source=t_c( l=.true. , x=r ) )

  select type(y); type is(t_c)
  write(*,*) "y%l = ", y%l
  end select

end program p

$ ifort test.f90 -o test
test.f90(27): error #6593: The number of expressions in a structure constructor differs from the number of components of the derived type.   [C_B]
  allocate( y , source=t_c( l=.true. , x=r ) )

I am using ifort Version 16.0.2.181 Build 20160204

The code is correct as far as I can tell, and gfortran compiles it.

Also, notice that altering the code as indicated in the comments makes the problem disappear - or at least the symptoms.

Marco


Viewing all articles
Browse latest Browse all 2746

Trending Articles



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