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

Couldn't use a integer parameter in submodules

MehdiChinoune
New Contributor I
2,063 Views

Both ifort and ifx don't accept using a parameter integer declared within the module to be used in function declarations.

This is the minimized reproducer:

module aaa
  implicit none
  integer, parameter :: dp = selected_real_kind(15)
  interface
    real(dp) module function foo(x)
      real(dp) :: x
    end function foo
  end interface
end module aaa

submodule(aaa) bbb
  implicit none
contains
  real(dp) module function foo(x)
    real(dp) :: x
    foo = x
  end function foo
end submodule bbb
$ ifx -c sub.f90
sub.f90(5): error #6683: A kind type parameter must be a compile-time constant.   [DP]
    real(dp) module function foo(x)
---------^
sub.f90(11): error #8765: Error in opening the compiled ancestor module file.   [AAA]
submodule(aaa) bbb
----------^
sub.f90(14): error #6683: A kind type parameter must be a compile-time constant.   [DP]
  real(dp) module function foo(x)
-------^
sub.f90(14): error #6115: A separate interface body must have been declared in the program unit or an ancestor of the program unit for the separate module procedure.   [FOO]
  real(dp) module function foo(x)
---------------------------^
sub.f90(15): error #6683: A kind type parameter must be a compile-time constant.   [DP]
    real(dp) :: x
---------^
compilation aborted for sub.f90 (code 1)
$ ifort -c sub.f90
sub.f90(5): error #6683: A kind type parameter must be a compile-time constant.   [DP]
    real(dp) module function foo(x)
---------^
sub.f90(11): error #8765: Error in opening the compiled ancestor module file.   [AAA]
submodule(aaa) bbb
----------^
sub.f90(14): error #6683: A kind type parameter must be a compile-time constant.   [DP]
  real(dp) module function foo(x)
-------^
sub.f90(14): error #6115: A separate interface body must have been declared in the program unit or an ancestor of the program unit for the separate module procedure.   [FOO]
  real(dp) module function foo(x)
---------------------------^
sub.f90(15): error #6683: A kind type parameter must be a compile-time constant.   [DP]
    real(dp) :: x
---------^
compilation aborted for sub.f90 (code 1)

 

0 Kudos
8 Replies
FortranFan
Honored Contributor III
2,055 Views

@MehdiChinoune ,

Please submit a support request toward bug resolution at Intel OSC if you have support subscription:

https://supporttickets.intel.com/servicecenter?lang=en-US

In the meantime, please consider using the RESULT clause as shown below as a workaround (by the way, please seek employing dummy argument INTENT in your actual codes in case you don't have them):

module aaa
  implicit none
  integer, parameter :: dp = selected_real_kind(15)
  interface
    module function foo(x) result(r)
      real(dp), intent(in) :: x
      real(dp) :: r
    end function foo
  end interface
end module aaa

submodule(aaa) bbb
  implicit none
contains
  module function foo(x) result(r)
    real(dp), intent(in) :: x
    real(dp) :: r
    r = x
  end function foo
end submodule bbb

 

0 Kudos
MehdiChinoune
New Contributor I
2,045 Views

I wouldn't post here if I have support subscription.

Thanks for the proposed workaround.

I always use intent(in), intent(out), pure, elemental...etc in my program But since It's just a minimal example I didn't bother adding those attributes.

0 Kudos
Arjen_Markus
Honored Contributor I
1,989 Views

Your code is lacking an import statement:

module aaa
  implicit none
  integer, parameter :: dp = selected_real_kind(15)
  interface
    real(dp) module function foo(x)
      import :: dp   !<== need to import the parameter explicitly
      real(dp) :: x
    end function foo
  end interface
end module aaa

submodule(aaa) bbb
  implicit none
contains
  real(dp) module function foo(x)
    real(dp) :: x
    foo = x
  end function foo
end submodule bbb

With this Intel Fortran does accept the code.

0 Kudos
Arjen_Markus
Honored Contributor I
1,986 Views

The gfortran compiler accepts the original code, but it seems to me that this is inconsistent with other interface declarations, where you do need to import a symbol like dp. I do not know which one is right.

0 Kudos
FortranFan
Honored Contributor III
1,967 Views

@Arjen_Markus ,

Your posts here perhaps reveal the root cause of the issue with Intel Fortran compiler i.e., the compiler developer(s) too have not looked adequately into the standard even though the change has only been in effect for over a dozen years now! 

The key aspect to notice in the reproducer in the original post is the MODULE clause with the function `foo`.  This is part of the functionality introduced way back in Fortran 2008 to support SUBMODULEs.  With such MODULE subprograms, the scoping rules are different and the IMPORT statement is not needed.  You could have realized this also from the workaround I posted upthread.

0 Kudos
Arjen_Markus
Honored Contributor I
1,902 Views

Hm, I overlooked your workaround.  So, the analysis of the code for submodules is only partially wrong. Still a bug though ;).

0 Kudos
Barbara_P_Intel
Employee
1,872 Views

I filed a bug report, CMPLRLLVM-36605, for you.

And, yes, you see the same messages with ifort and ifx since they share the same front-end.



0 Kudos
Barbara_P_Intel
Employee
966 Views

I compiled with ifx and ifort that were released last week with 2024.1. Those erroneous error messages are gone.

Please try the new compilers.



0 Kudos
Reply