- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code triggers a spurious compiler error.
My understanding is that the variable J is "the name of one or more entities accessible in the host scoping unit" (per the documentation) and therefore its use in the IMPORT statement should be valid.
MODULE M
IMPLICIT NONE (TYPE, EXTERNAL)
INTEGER, PARAMETER :: J = 1
END MODULE M
MODULE N
USE M
IMPLICIT NONE (TYPE, EXTERNAL)
INTERFACE
MODULE SUBROUTINE S
END SUBROUTINE S
END INTERFACE
END MODULE N
SUBMODULE (N) S
IMPORT, ONLY : S, J ! This line triggers a compiler error.
IMPLICIT NONE (TYPE, EXTERNAL)
CONTAINS
MODULE SUBROUTINE S
IMPLICIT NONE (TYPE, EXTERNAL)
WRITE(*, *) J
END SUBROUTINE S
END SUBMODULE S
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'll have to get our Standards members to look at this one. First, ifx is in agreement with gfortran 13 and Nag that this IMPORT is illegal. That is not to say that all 3 are right. Perhaps all 3 compilers are getting this wrong. Surely this deserves a more in-depth analysis with the Standard experts. @OP1 your code is usually conformant so I'm inclined to side with you that this should be legal. My reading would suggest the IMPORT has to go in the INTERFACE in MODULE N. But with submodules my intuition may be flawed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
F2018 had significant changes in IMPORT and from my initial reading I think it may be valid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@OP1 Jon Steidel agrees with you, it seems valid. I will start a bug report for ifx. His further analysis
Fortran 2018 expanded the use of the IMPORT statement to allow it in BLOCKs, internal procedures, and module procedures. There is a constraint
C8100 An IMPORT statement shall not appear in the scoping unit of a main-program, external-subprogram, module, or block-data
which does not prohibit it in a submodule. Then there is another constraint
C8103 IMPORT, NONE shall not appear in the scoping unit of a submodule
So, it seems that this test case is valid. I wrote a couple simple tests and it appears NAG and gfortran have not yet implemented this F2018 feature.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@andrew_4619 and Jon Steidel pointed you in the right direction. And you are very likely correct in that both gfortran and NAG Fortran might yet have to catch up to this Fortran 2018 facility. But here I thought I saw a blurb some place NAG Fortran is now conformant with Fortran 2018; if so, this is likely a bug in that compiler.
Anyways, you can pass this simpler variant to the Intel Fortran team which is processed as expected by IFX 2024.1.0 version (and that is really cool). So the issue here is very likely when it comes to entities in a MODULE that are introduced via USE association rather than declared in the module itself.
MODULE N
IMPLICIT NONE (TYPE, EXTERNAL)
INTEGER, PARAMETER :: J = 1
INTERFACE
MODULE SUBROUTINE S
END SUBROUTINE S
END INTERFACE
END MODULE N
SUBMODULE (N) S
IMPORT, ONLY : S, J
IMPLICIT NONE (TYPE, EXTERNAL)
CONTAINS
MODULE SUBROUTINE S
IMPLICIT NONE (TYPE, EXTERNAL)
WRITE(*, *) J
END SUBROUTINE S
END SUBMODULE S
C:\temp>ifx /c /standard-semantics /free n.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.1.0 Build 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
C:\temp>

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page