public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Boyce at engineer dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/108650] New: Error: IMPORT statement only permitted in an INTERFACE body | but it should be allowed in any contained routine to control scope
Date: Fri, 03 Feb 2023 00:22:41 +0000	[thread overview]
Message-ID: <bug-108650-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108650

            Bug ID: 108650
           Summary: Error: IMPORT statement only permitted in an INTERFACE
                    body | but it should be allowed in any contained
                    routine to control scope
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Boyce at engineer dot com
  Target Milestone: ---

Created attachment 54398
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54398&action=edit
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

             reply	other threads:[~2023-02-03  0:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03  0:22 Boyce at engineer dot com [this message]
2023-02-03  7:19 ` [Bug fortran/108650] " kargl at gcc dot gnu.org
2023-06-02 15:24 ` kargl at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108650-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).