Created attachment 54398 [details] Source code, bash file to compile, and error message import should be allowed within contained subroutines to control access to global variables from parent routine. From: http://armnlib.uqam.ca/PDF/The_New_Features_of_Fortran_2018.pdf The import statement can be used in a contained subprogram or block construct to control host association. It does not look like import is on the F2018 standard website: https://gcc.gnu.org/wiki/Fortran2018Status but it should work within contained routines: https://www.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/language-reference/a-to-z-reference/h-to-i/import.html I tested this code with with 11.3.0 and 12.1.0 I attached the following source code: -------------------------------------------- module test implicit none ! save integer:: a = 0 integer:: b = 0 integer:: c = 0 ! contains ! subroutine sub1(x) import:: a ! raises error that import only allowed in interface real, intent(inout):: x a = a + 1 x = x + 1.0 end subroutine ! subroutine sub2(x) real, intent(inout):: x x = x + 1.0 ! contains ! function positive(x) result(ans) import, none ! raises error that import only allowed in interface real, intent(in):: x logical:: ans ans = x>=0.0 end function end subroutine end module program MAIN use test implicit none real:: var var = 1.0 call sub1(var) call sub2(var) ! end program -------------------------------------------- $ gfortran --version Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gfortran-12 main.f90 12 | import:: a ! raises error that import only alowed in interface | 1 Error: IMPORT statement at (1) only permitted in an INTERFACE body main.f90:25:15: 25 | import, none | 1 Error: IMPORT statement at (1) only permitted in an INTERFACE body main.f90:34:7: ------------------------------------------------------------------------------- $ gfortran-12 --version GNU Fortran (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gfortran-12 main.f90 25 | import, none | 1 Error: IMPORT statement at (1) only permitted in an INTERFACE body
This is duplicate of at least one other bug report.
Dup. *** This bug has been marked as a duplicate of bug 106035 ***