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

Unimplemented F2008 feature or compiler bug in ifx 2024.0?

NCarlson
New Contributor I
912 Views

Starting with the Fortran 2008 standard, a dummy argument with the allocatable attribute is distinguishable from one with the pointer attribute (see F2018 15.4.3.4.5) when defining a generic interface.  Hence the following example should be conforming:

module secure_hash_factory

  implicit none
  private

  public :: secure_hash, new_secure_hash

  type, abstract :: secure_hash
  end type

  interface new_secure_hash
    procedure new_secure_hash_alloc, new_secure_hash_ptr
  end interface

contains

  subroutine new_secure_hash_alloc(hash)
    class(secure_hash), allocatable, intent(out) :: hash
    print *, 'allocatable'
  end subroutine

  subroutine new_secure_hash_ptr(hash)
    class(secure_hash), pointer, intent(out) :: hash
    print *, 'pointer'
  end subroutine

end module

use secure_hash_factory
class(secure_hash), allocatable :: h1
class(secure_hash), pointer :: h2
call new_secure_hash(h1)
call new_secure_hash(h2)
end

Indeed, if the module is compiled by itself, ifx 2024.0 reports no error. However when the module is used by another program unit and the generic function referenced (as in the main program of the example), the compiler issues the following strange error:

$ ifx -c intel-20231123.f90
intel-20231123.f90: error #5286: Ambiguous generic interface NEW_SECURE_HASH: previously declared specific procedure SECURE_HASH_FACTORY::NEW_SECURE_HASH_ALLOC is not distinguishable from this declaration. [SECURE_HASH_FACTORY::NEW_SECURE_HASH_PTR]
intel-20231123.f90(32): error #7496: A non-pointer actual argument shall have a TARGET attribute when associated with a pointer dummy argument.   [H1]
call new_secure_hash(h1)
---------------------^
compilation aborted for intel-20231123.f90 (code 1)

Is this a case of a not-yet-completed F2008 feature or a compiler bug?  I suspect the latter.  Note that NAG and GFortran both compile (and run) the example without error. 

5 Replies
FortranFan
Honored Contributor III
861 Views

It does look like an oversight.

Intel compiler team will perhaps add this simple variant to the test case also?

   generic :: s => sa, sp
   integer, allocatable :: x
   integer, pointer :: y
   call s( x )
   call s( y )
contains
   subroutine sa( a )
      integer, allocatable, intent(out) :: a
      a = 42
   end subroutine 
   subroutine sp( a )
      integer, pointer, intent(out) :: a
      a => null()
   end subroutine
end
C:\temp>ifort /c /standard-semantics /free p.f
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.10.0 Build 20230609_000000
Copyright (C) 1985-2023 Intel Corporation.  All rights reserved.

p.f(1): error #5286: Ambiguous generic interface S: previously declared specific procedure SA is not distinguishable from this declaration. [SP]
   generic :: s => sa, sp
-----------------------^
p.f(4): error #7496: A non-pointer actual argument shall have a TARGET attribute when associated with a pointer dummy argument.   [X]
   call s( x )
-----------^
compilation aborted for p.f (code 1)
Barbara_P_Intel
Employee
790 Views

Thank you, gentlemen!

I filed a bug report, CMPLRLLVM-53947, for this issue.

I do have a question. Is this an F2008 feature or F2018? I'm curious because, @NCarlson, you wrote F2008, but cited F2018. I don't spend a lot of time reading the standard.



0 Kudos
NCarlson
New Contributor I
785 Views

It is F2008; see 12.4.3.4.5 in that standard.

0 Kudos
Barbara_P_Intel
Employee
774 Views

Thank you, @NCarlson!


0 Kudos
Barbara_P_Intel
Employee
457 Views

The erroneous error messages you reported are fixed in ifx 2024.2.0 that is planned for release in mid-2024. Watch for that release!



0 Kudos
Reply