Bug 46310 - [F03] gfortran wrongly treats INTERFACE BLOCK and not INTERFACE BODY as scoping unit
Summary: [F03] gfortran wrongly treats INTERFACE BLOCK and not INTERFACE BODY as scopi...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: F2003 29670
  Show dependency treegraph
 
Reported: 2010-11-05 08:43 UTC by Tobias Burnus
Modified: 2018-10-13 12:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-09-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-11-05 08:43:58 UTC
Reported by Damian at  http://gcc.gnu.org/ml/fortran/2010-11/msg00081.html / http://gcc.gnu.org/ml/fortran/2010-11/msg00082.html

Reduced example:
!---------------------------------
module foo_module
 implicit none
 interface
   real function func_interface()
   end function
   subroutine bar_interface(f)
     implicit none
     procedure(func_interface), intent(in) :: f
   end subroutine
 end interface
end module
!---------------------------------

The program is invalid without "import func_interface".

The reason is that not the interface block but the interface body is a scoping unit and host association only occurs using the IMPORT statement.

While many compilers (crayftn, nagf95, xlf, g95) correctly reject the program, gfortran happily compiles it.

Fortran 2008 defines:

"1.3.124 scoping unit -- BLOCK construct, derived-type definition, interface body, program unit, or subprogram, excluding all nested scoping units in it"
Comment 1 Dominique d'Humieres 2010-11-05 08:59:14 UTC
> The program is invalid without "import func_interface".
> 
> The reason is that not the interface block but the interface body is a scoping
> unit and host association only occurs using the IMPORT statement.
> 
> While many compilers (crayftn, nagf95, xlf, g95) correctly reject the program,
> gfortran happily compiles it.

With an unpatched trunk, I get an error in both cases:

[macbook] f90/bug% gfcp -v
Using built-in specs.
COLLECT_GCC=gfcp
COLLECT_LTO_WRAPPER=/opt/gcc/gcc4.6p/libexec/gcc/x86_64-apple-darwin10/4.6.0/lto-wrapper
Target: x86_64-apple-darwin10
Configured with: ../p_work/configure --prefix=/opt/gcc/gcc4.6p --mandir=/opt/gcc/gcc4.6p/share/man --infodir=/opt/gcc/gcc4.6p/share/info --build=x86_64-apple-darwin10 --host=x86_64-apple-darwin10 --target=x86_64-apple-darwin10 --enable-languages=c,lto,fortran --with-gmp=/opt/sw64 --with-libiconv-prefix=/opt/sw64 --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --with-cloog=/opt/sw64 --with-ppl=/opt/sw64 --with-mpc=/opt/sw64 --enable-checking=release
Thread model: posix
gcc version 4.6.0 20101031 (experimental) [trunk revision 166102] (GCC) 
[macbook] f90/bug% gfcp pr46310.f90
pr46310.f90:6.29:

   subroutine bar_interface(f)
                             1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'f' at (1)
[macbook] f90/bug% gfcp pr46310_db.f90
pr46310_db.f90:6.29:

   subroutine bar_interface(f)
                             1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'f' at (1)
[macbook] f90/bug% diff -up pr46310.f90 pr46310_db.f90
--- pr46310.f90	2010-11-05 09:51:53.000000000 +0100
+++ pr46310_db.f90	2010-11-05 09:53:55.000000000 +0100
@@ -4,6 +4,7 @@ module foo_module
    real function func_interface()
    end function
    subroutine bar_interface(f)
+     import func_interface
      implicit none
      procedure(func_interface), intent(in) :: f
    end subroutine
Comment 2 Tobias Burnus 2010-11-05 09:25:12 UTC
(In reply to comment #1)
> With an unpatched trunk, I get an error in both cases:

> Error: PROCEDURE attribute conflicts with INTENT attribute in 'f' at (1)

That makes sense; thus, either remove INTENT(IN) from or add POINTER to the example. Sorry for the wrong/incomplete example.

(I can reproduce the result - and seemingly missed the recompile with gfortran after the modification (needed for NAG 5.1); with NAG the intended error hides the INTENT error.)
Comment 3 Dominique d'Humieres 2015-09-08 09:20:38 UTC
> That makes sense; thus, either remove INTENT(IN) from or add POINTER
> to the example. Sorry for the wrong/incomplete example.

Confirmed with

module foo_module
 implicit none
 interface
   real function func_interface()
   end function
   subroutine bar_interface(f)
     import func_interface
     implicit none
     procedure(func_interface) :: f
   end subroutine
 end interface
end module