Bug 27318 - gfortran should warn if a interface does not match
Summary: gfortran should warn if a interface does not match
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P3 enhancement
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: diagnostic
: 45086 45654 (view as bug list)
Depends on:
Blocks: 29670
  Show dependency treegraph
 
Reported: 2006-04-25 18:12 UTC by tobias.burnus
Modified: 2020-07-05 18:16 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-04-25 18:39:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tobias.burnus 2006-04-25 18:12:55 UTC
Test case:
------------------------------
module test
implicit none
interface
   subroutine hello(n)
     integer :: n
   end subroutine hello
end interface
end module test

subroutine hello(n)
  integer, intent(in) :: n
  integer :: i
  do i = 1,n; print *, 'hello'; end do
end subroutine hello
------------------------------

In the interface, "n" is implicitly "intent(inout)".
gfortran -Wall does not warn, NAG f95 does:
------------
Error: test3.f90: Inconsistent INTERFACE block for procedure HELLO from TEST
       Argument N (no. 1) has a different INTENT
[f95 error termination]
------------
Comment 1 Andrew Pinski 2006-04-25 18:39:13 UTC
Confirmed.
Comment 2 Daniel Franke 2010-12-28 18:23:33 UTC
*** Bug 45654 has been marked as a duplicate of this bug. ***
Comment 3 Daniel Franke 2010-12-28 18:26:20 UTC
*** Bug 45086 has been marked as a duplicate of this bug. ***
Comment 4 Thomas Koenig 2020-06-13 17:17:19 UTC
This is also not caught:

module test
implicit none
interface
   subroutine hello(n)
     integer :: n
   end subroutine hello
end interface
contains
  subroutine bar()
     call hello(3)
  end subroutine bar
end module test

subroutine hello(r)
  real :: r
  integer :: i
  do i = 1, int(r); print *, 'hello'; end do
end subroutine hello
Comment 5 Thomas Koenig 2020-06-14 10:17:32 UTC
To celebrate this PR's 14th birthday (if a bit late), a patch was posted:

https://gcc.gnu.org/pipermail/gcc-patches/2020-June/548045.html
Comment 6 GCC Commits 2020-07-05 18:15:07 UTC
The master branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>:

https://gcc.gnu.org/g:cc9a9229285a26ac12bc8de53237ce9c4d42f867

commit r11-1814-gcc9a9229285a26ac12bc8de53237ce9c4d42f867
Author: Thomas Koenig <tkoenig@gcc.gnu.org>
Date:   Sun Jul 5 20:11:35 2020 +0200

    Test global identifiers against what is specified interfaces.
    
    Apart from calling gfc_compare_interfaces to check interfaces against
    global identifiers, this also sets and check a few sym->error flags
    to avoid duplicate error messages.  I thought about issuing errors
    on mismatched interfaces, but when the procedure is not invoked,
    a warning should be enough to alert the user.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/27318
            * frontend-passes.c (check_against_globals): New function.
            (gfc_check_externals): Split; also invoke check_against_globals
            via gfc_traverse_ns.
            (gfc_check_externals0): Recursive part formerly in
            gfc_check_externals.
            * resolve.c (resolve_global_procedure): Set sym->error on
            interface mismatch.
            * symbol.c (ambiguous_symbol): Check for, and set sym->error.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/27318
            * gfortran.dg/error_recovery_1.f90: Adjust test case.
            * gfortran.dg/use_15.f90: Likewise.
            * gfortran.dg/interface_47.f90: New test.
Comment 7 Thomas Koenig 2020-07-05 18:16:28 UTC
Fixed, closing.