Bug 108650 - Error: IMPORT statement only permitted in an INTERFACE body | but it should be allowed in any contained routine to control scope
Summary: Error: IMPORT statement only permitted in an INTERFACE body | but it should b...
Status: RESOLVED DUPLICATE of bug 106035
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2023-02-03 00:22 UTC by Scott Boyce
Modified: 2023-06-02 15:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Source code, bash file to compile, and error message (1.33 KB, application/x-zip-compressed)
2023-02-03 00:22 UTC, Scott Boyce
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Scott Boyce 2023-02-03 00:22:41 UTC
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
Comment 1 kargls 2023-02-03 07:19:54 UTC
This is duplicate of at least one other bug report.
Comment 2 kargls 2023-06-02 15:24:16 UTC
Dup.

*** This bug has been marked as a duplicate of bug 106035 ***