From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B79CC3858C74; Fri, 3 Feb 2023 00:22:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B79CC3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675383762; bh=Mum8nm0U7mNTdEhRkpQVnMA36KRZqYiYJ+2MnZtjg9Y=; h=From:To:Subject:Date:From; b=O7MI4i+/JKKBNw0nLGiFuZCDnEw46dE4zQ2xhLIQcnVVvyvAPLyC03qCpyYPLaPFN iPKhRl6WmEb6FVxbasv1RSBY8Ojt3Vwa2Y8WnD8fHnxI0Y5T46CoLNRMdWzHokFlFH e0Y/MpnImNTmEjC43UbfVJIPOAr21vWrQmszrpM4= From: "Boyce at engineer dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Boyce at engineer dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108650 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=3D54398&action=3Dedit Source code, bash file to compile, and error message import should be allowed within contained subroutines to=20 control access to global variables from parent routine. From: http://armnlib.uqam.ca/PDF/The_New_Features_of_Fortran_2018.pdf=20 The import statement can be used in a contained subprogram or=20 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-compi= ler-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=20 I attached the following source code: -------------------------------------------- module test implicit none ! save integer:: a =3D 0 integer:: b =3D 0 integer:: c =3D 0 ! contains ! subroutine sub1(x) import:: a ! raises error that import only allowed in interface real, intent(inout):: x a =3D a + 1 x =3D x + 1.0 end subroutine ! subroutine sub2(x) real, intent(inout):: x x =3D 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 =3D x>=3D0.0 end function end subroutine end module program MAIN use test implicit none real:: var var =3D 1.0 call sub1(var) call sub2(var) !=20 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=20 12 | import:: a ! raises error that import only alowe= d 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=20 25 | import, none | 1 Error: IMPORT statement at (1) only permitted in an INTERFACE body=