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

Overloading the concatenation operator fails with Intel Fortran oneAPI 2021.04

Arjen_Markus
Honored Contributor I
859 Views

I have come across an odd problem with overloading the concatenation operator. Unfortunately I have been unable to construct a small example that will show the problem, so I append the entire program instead (note: this is work in progress ;)). The gfortran compiler is happy enough to build the program and it works as I expected.

These are the error messages I get:

Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.4.0 Build 20210910_000000
Copyright (C) 1985-2021 Intel Corporation.  All rights reserved.


d:\fortran\testjes\moa>ifort -exe:test_moa_view_ndim moa_view_ndim.f90 view_general.obj
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.4.0 Build 20210910_000000
Copyright (C) 1985-2021 Intel Corporation.  All rights reserved.

moa_view_ndim.f90(345): error #6054: A CHARACTER data type is required in this context.   [I]
    z = i // j
--------^
moa_view_ndim.f90(345): error #6054: A CHARACTER data type is required in this context.   [J]
    z = i // j
-------------^
moa_view_ndim.f90(345): error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.
    z = i // j
----------^
moa_view_ndim.f90(366): error #6054: A CHARACTER data type is required in this context.   [AA]
    z = aa // bb
--------^
moa_view_ndim.f90(366): error #6054: A CHARACTER data type is required in this context.   [BB]
    z = aa // bb
--------------^
moa_view_ndim.f90(366): error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.
    z = aa // bb
-----------^
moa_view_ndim.f90(366): error #6366: The shapes of the array expressions do not conform.   [Z]
    z = aa // bb
----^
compilation aborted for moa_view_ndim.f90 (code 1)

As you can see, there is no message about the overloaded // operator itself, which is defined in the module as:

    public :: operator(//)
    interface operator(//)
        module procedure catenate_array_array, catenate_array_view, catenate_view_array, catenate_view_view
    end interface

But actually applying it causes the error messages.

My attempt at a small reproducer:

module concatenation
    implicit none

    public :: two_ints, operator(//)

    type :: two_ints
        integer, dimension(4) :: value
    end type two_ints

    interface operator(//)
        module procedure concat
    end interface
contains
function concat( a, b )
    integer, dimension(:), intent(in) :: a, b
    type(two_ints)                    :: concat

    concat%value(1:2) = a
    concat%value(3:4) = b
end function concat

end module concatenation

program chk_concat
    use concatenation

    type(two_ints) :: c
    integer, dimension(2) :: a, b

    a = [1, 2]
    b = [3, 4]

    c = a // b
    write(*,*) c

end program chk_concat

causes no complaints whatsoever and works as expected.

1 Reply
Arjen_Markus
Honored Contributor I
763 Views

Does anyone have a solution for this problem? (Other than using a user-defined operation - I like the syntax of the // operation for this)

0 Kudos
Reply