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

Why are executable statements allowed in interface blocks?

OP1
New Contributor II
922 Views

I realized by accident today that it is possible to have executable statements in an interface block. What is the purpose of this?

The code below compiles fine with the 2021.7.0 ifort compiler. It cannot be run (understandably) since the procedure S is not provided. Still, the presence of the WRITE statement in the interface block feels so strange.

I have probably written tens of thousands of interface blocks for module procedures (the introduction of submodules in fortran was truly the best thing since sliced bread) and never realized this quirk's existence.

 

MODULE M
IMPLICIT NONE (TYPE, EXTERNAL)
INTERFACE
    SUBROUTINE S(X)
    IMPLICIT NONE (TYPE, EXTERNAL)
    INTEGER :: X
    WRITE(*, *) 2*X
    END SUBROUTINE S
END INTERFACE
END MODULE M

PROGRAM P
USE M
IMPLICIT NONE
CALL S(1)
END PROGRAM P

 

0 Kudos
7 Replies
Steve_Lionel
Honored Contributor III
916 Views

There is no purpose - it's not allowed by the language. That ifort doesn't complain is a bug.

0 Kudos
OP1
New Contributor II
909 Views

Thanks Steve. That did sound quite fishy indeed!

@Barbara_P_Intel , here is a bug for you   ... and I also checked that both ifort and ifx exhibit this behavior.

0 Kudos
Barbara_P_Intel
Moderator
898 Views

What would I do without you guys? I filed a bug, CMPLRLLVM-42318. I'll let you know when I know it's fixed.



FortranFan
Honored Contributor II
881 Views

Hi @Barbara_P_Intel ,

Can we have a quick chat here about this issue but in terms of the support incident you filed, can we pretend this discussion never happened!!?  Meaning, let your submission CMPLRLLVM-42318 remain as a bug report!!?

This is because the language standard for Fortran does not indicate a numbered constraint prohibiting an execution-part in an INTERFACE body and thus a processor is not compelled to include the capability to diagnose and report the presence of the offending part.  This may incline someone amongst the Intel Fortran to see this as a feature request instead!

However it is nice that Intel Fortran does report compile-time errors with certain executable statements in an interface body even though for some odd reason the WRITE statement flies under the radar c.f. line C in the snippet below versus A or B.

 

   interface
      subroutine sub()
         i = 1         !<-- A: error #6622
         !print *, i   !<-- B: error #6622
         !write(*,*) i !<-- C: no error
      end subroutine
   end interface
end 
C:\temp>ifx /c /standard-semantics p.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2022.2.0 Build 20220730
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

p.f90(3): error #6622: This statement is invalid in an INTERFACE block.
         i = 1        !<-- A
---------^
compilation aborted for p.f90 (code 1)

C:\temp>

 

You can then try to answer, is it a feature or bug!!?

0 Kudos
Steve_Lionel
Honored Contributor III
857 Views

@FortranFan , I'm puzzled by your comment. The numbered syntax rules for an interface block do not allow for an executable statement. See 15.4.3.2 in F2018. The compiler is required to be able to diagnose code that doesn't conform, and in the absence of a deliberate extension, it should here.

0 Kudos
JohnNichols
Valued Contributor III
827 Views

Every time I see my Doctor, I am given a lecture on do not eat sliced bread.  Yesterday was a further example. 

The latest iteration of Intel ARC popped up today and said -- I am lonely you do not have any games.  

Fortran is simple, the stuff around it is hard. 

 

0 Kudos
Barbara_P_Intel
Moderator
463 Views

I now see error messages for both ifx and ifort in the compilers that were released this week as part of oneAPI HPC Toolkit 2023.2.

Please check out this new release.

$ ifx --version
ifx (IFX) 2023.2.0 20230622
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

$ ifx -c interface.f90
interface.f90(7): error #6622: This statement is invalid in an INTERFACE block.
    WRITE(*, *) 2*X
----^
compilation aborted for interface.f90 (code 1)

$ ifort --version
ifort (IFORT) 2021.10.0 20230609
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

$ ifort -c interface.f90
interface.f90(7): error #6622: This statement is invalid in an INTERFACE block.
    WRITE(*, *) 2*X
----^
compilation aborted for interface.f90 (code 1)
$
0 Kudos
Reply