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

Compiler throws error on generic interface (ambiguous generic interface) / fix by reordering items

jeffhole
Beginner
100 Views

Compilerifx (IFX) 2024.2.0 20240602 (ifx --version)

OS Rocky Linux 8.9 (Green Obsidian)

 

I have a generic interface that the compiler does not like. Here is the source that produces the error.

 

! file: produce_error.f90
module CalculateModule
    use, intrinsic :: iso_c_binding
    implicit none
    private
    public :: calculate

    interface calculate
        module procedure :: calculate_standard
        module procedure :: calculate_prealloc_standard
        module procedure :: calculate_prealloc_pointer
        module procedure :: calculate_pointer
    end interface

    interface
        module subroutine calculate_standard(x1,x2,x3,opt_1,opt_2)
            real(4), intent(in)                 :: x1(:), x2(:)
            real(4), intent(inout), allocatable :: x3(:)
            integer,     intent(in), optional   :: opt_1
            type(c_ptr), intent(in), optional   :: opt_2(3)
        end subroutine

        module subroutine calculate_pointer(x1,x2,x3,opt_1,opt_2)
            real(4), intent(in)               :: x1(:), x2(:)
            real(4), intent(inout), pointer   :: x3(:)
            integer,     intent(in), optional :: opt_1
            type(c_ptr), intent(in), optional :: opt_2(3)
        end subroutine

        module subroutine calculate_prealloc_standard(x1,x2,x3,x1full,x2full,x3full,fx1,fx2,fx3,opt_1,opt_2)
            real(4), intent(in)                    :: x1(:), x2(:)
            real(4), intent(inout), allocatable    :: x3(:)
            complex(4), allocatable, intent(inout) :: x1full(:), x2full(:)
            complex(4), allocatable, intent(inout) :: fx1(:), fx2(:), fx3(:)
            complex(4), allocatable, intent(inout) :: x3full(:)
            integer,     intent(in), optional      :: opt_1
            type(c_ptr), intent(in), optional      :: opt_2(3)
        end subroutine

        module subroutine calculate_prealloc_pointer(x1,x2,x3,x1full,x2full,x3full,fx1,fx2,fx3,opt_1,opt_2)
            real(4), intent(in)                    :: x1(:), x2(:)
            real(4), intent(inout), pointer        :: x3(:)
            complex(4), allocatable, intent(inout) :: x1full(:), x2full(:)
            complex(4), allocatable, intent(inout) :: fx1(:), fx2(:), fx3(:)
            complex(4), allocatable, intent(inout) :: x3full(:)
            integer,     intent(in), optional      :: opt_1
            type(c_ptr), intent(in), optional      :: opt_2(3)
        end subroutine
    end interface
end module

 

Run the compiler and here is the output

 

ifx -c produce_error.f90
produce_error.f90(23): error #5286: Ambiguous generic interface CALCULATE: previously declared specific procedure CALCULATE_STANDARD is not distinguishable from this declaration. [CALCULATE_POINTER]
        module subroutine calculate_pointer(x1,x2,x3,opt_1,opt_2)
--------------------------^
compilation aborted for produce_error.f90 (code 1)

 

Workaround

The strange thing is that reorganizing the items in the generic interface makes the compiler happy:

 

! BAD
interface calculate
    module procedure :: calculate_standard
    module procedure :: calculate_prealloc_standard
    module procedure :: calculate_prealloc_pointer
    module procedure :: calculate_pointer
end interface

! GOOD
interface calculate
    module procedure :: calculate_standard
    module procedure :: calculate_pointer
    module procedure :: calculate_prealloc_standard
    module procedure :: calculate_prealloc_pointer
end interface

 

I've attached the full workaround source.

Labels (1)
0 Kudos
0 Replies
Reply