Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28477 Discussions

Array construction error when element involves overload operator

Zuodong_Y_
Novice
463 Views

 

 

module test
	implicit none
	type c
		integer :: tp=0
	contains
		procedure :: times
		generic :: operator(*) => times
	end type
	type x
		type(c) :: cc(2)
	end type
contains
	function times(c1,c2) result(cc)
		class(c), intent(in) :: c1
		type(c), intent(in) :: c2
		type(x) :: cc
		cc%cc(1)=c1
		cc%cc(2)=c2
	end function
end module
program main
	use test
	implicit none
	type(x) :: cc(1)
	integer :: i=1
	cc=[c(1)*c(1)] ! not working
	cc=[c(i)*c(i)] ! working
	cc=[x([c(i),c(i)])] ! working
end program

above example code cause "error #6355: This binary operation is invalid for this data type" when compiled with ifort version 2021.10.0. Any idea why? Thanks!!!

0 Kudos
1 Solution
Barbara_P_Intel
Moderator
345 Views

Thanks for reporting the issue with the second program. I filed a bug report on that version, CMPLRLLVM-55846.

As @Steve_Lionel wrote, the first program compiles without an error message with the current compiler release.


View solution in original post

3 Replies
Zuodong_Y_
Novice
429 Views

Following code also cause the same compilation error

module test
	implicit none
	type c
		integer :: tp=0
	contains
		procedure :: times
		generic :: operator(*) => times
	end type
	type x
		type(c) :: cc(2)
	end type
	type t
		type(x) :: cc
	end type
contains
	function times(c1,c2) result(cc)
		class(c), intent(in) :: c1
		type(c), intent(in) :: c2
		type(x) :: cc
		cc%cc(1)=c1
		cc%cc(2)=c2
	end function
end module
program main
	use test
	implicit none
	type(t) :: a
	integer :: i=1
	a=t(c(1)*c(1)) ! not working
	a=t(c(i)*c(i)) ! working
end program

 

 

Steve_Lionel
Honored Contributor III
405 Views

The first example works for me with the current ifort:

D:\Projects>ifort -c t.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.11.1 Build 20231117_000000
Copyright (C) 1985-2023 Intel Corporation.  All rights reserved.

ifort: remark #10448: Intel(R) Fortran Compiler Classic (ifort) is now deprecated and will be discontinued late 2024. Intel recommends that customers transition now to using the LLVM-based Intel(R) Fortran Compiler (ifx) for continued Windows* and Linux* support, new language support, new language features, and optimizations. Use '/Qdiag-disable:10448' to disable this message.

D:\Projects>

 The second one still fails, though - also with ifx, though that's expected. Peculiar.

D:\Projects>ifx -c t.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.2 Build 20231213
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

t.f90(29): error #6355: This binary operation is invalid for this data type.
        a=t(c(1)*c(1)) ! not working
------------^
t.f90(29): error #6355: This binary operation is invalid for this data type.
        a=t(c(1)*c(1)) ! not working
-----------------^
compilation aborted for t.f90 (code 1)
Barbara_P_Intel
Moderator
346 Views

Thanks for reporting the issue with the second program. I filed a bug report on that version, CMPLRLLVM-55846.

As @Steve_Lionel wrote, the first program compiles without an error message with the current compiler release.


Reply