Bug 30096 - [4.1 only] Interface bug: gfortran falsely detect ambigious interface, scoping problem?
Summary: [4.1 only] Interface bug: gfortran falsely detect ambigious interface, scopin...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords:
Depends on: 30068
Blocks:
  Show dependency treegraph
 
Reported: 2006-12-06 21:57 UTC by Harald Anlauf
Modified: 2006-12-21 15:07 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-12-08 21:01:59


Attachments
Interface bug demo (289 bytes, text/plain)
2006-12-06 21:58 UTC, Harald Anlauf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2006-12-06 21:57:39 UTC
Hi,

the attached legal code fails to compile with gfortran.

% gfortran gfcbug48.f90
gfcbug48.f90:30.76:

   use module2, only : inverse     ! <-- gfortran does handle this properly
                                                                          1 
Error: Ambiguous interfaces 'inverse_submatrix' and 'inverse_submatrix' in gener
ic interface 'inverse' at (1)
gfcbug48.f90:30.76:

   use module2, only : inverse     ! <-- gfortran does handle this properly
                                                                          1 
Error: Ambiguous interfaces 'inverse_submatrix' and 'inverse_submatrix' in gener
ic interface 'inverse' at (1)
Comment 1 Harald Anlauf 2006-12-06 21:58:42 UTC
Created attachment 12762 [details]
Interface bug demo
Comment 2 Tobias Burnus 2006-12-06 22:20:48 UTC
I think this is a doublicate of one of symbol ambiguity bugs, which confuse Paul and me the last days.
[The problem is not primarily the implementation, the problem is what is right and what is wrong according to the standard. Even real Fortran standard experts cannot agree, see the link to computer.languages.fortran in PR30068, if you are interested.]

In any case, it works with my current SVN and the (preliminary) patch from
PR 30068 applied.
Comment 3 Paul Thomas 2006-12-07 18:15:33 UTC
(In reply to comment #2)
> I think this is a doublicate of one of symbol ambiguity bugs, which confuse

It is related - the latest version incorrectly gives a warning that the interfaces are ambiguous.

> In any case, it works with my current SVN and the (preliminary) patch from
> PR 30068 applied.
> 

What is compiled does not work: See below

Paul

module module1
  interface inverse
     module procedure y
  end interface
contains
  function y (X)
    real                        :: Y, X
    Y = X
  end function y
end module module1

module module2
  interface inverse
     module procedure y
  end interface
contains
  function y (X)
    real                        :: Y, X
    Y = 2*X
  end function y
end module module2

program gfcbug48
  use module1, only : inverse       ! We need this implementation in the main program
  call sub ()
  print *, inverse(1.0)
contains
  subroutine sub ()
    use module2, only : inverse     ! <-- gfortran does handle this properly
    print *, inverse(1.0)
  end subroutine sub
end program gfcbug48

Comment 4 Paul Thomas 2006-12-08 21:01:59 UTC
(In reply to comment #3)
> (In reply to comment #2)

Fixed by the latest version of the pr30068 patch.

Paul


Comment 5 patchapp@dberlin.org 2006-12-09 10:01:07 UTC
Subject: Bug number PR30096

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-12/msg00605.html
Comment 6 Paul Thomas 2006-12-09 21:13:52 UTC
Subject: Bug 30096

Author: pault
Date: Sat Dec  9 21:13:29 2006
New Revision: 119697

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119697
Log:
2006-12-09  Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29975
	PR fortran/30068
	PR fortran/30096
	* interface.c (compare_type_rank_if): Reject invalid generic
	interfaces.
	(check_interface1): Give a warning for nonreferred to ambiguous
	interfaces.
	(check_sym_interfaces): Check whether an ambiguous interface is
	referred to.  Do not check host associated interfaces since these
	cannot be ambiguous with the local versions.
	(check_uop_interface, gfc_check_interfaces): Update call to
	check_interface1.
	* symbol.c (gfc_get_sym_tree, gfc_get_sym_tree): Allow adding
	unambiguous procedures to generic interfaces.
	* gfortran.h (symbol_attribute): Added use_only and
	ambiguous_interfaces.
	* module.c (load_need): Set the use_only flag, if needed.
	* resolve.c (resolve_fl_procedure): Warn for nonreferred
	interfaces.
	* expr.c (find_array_section): Fix initializer array contructor.


2006-12-09  Paul Thomas <pault@gcc.gnu.org>
	    Tobias Burnus <burnus@gcc.gnu.org>

	PR fortran/29975
	PR fortran/30068
	* gfortran.dg/interface_4.f90: Test adding procedure to generic
	interface.
	* gfortran.dg/interface_5.f90: Test warning for not-referenced-to
	ambiguous interfaces.
	* gfortran.dg/interface_6.f90: Test invalid, ambiguous interface.
	* gfortran.dg/interface_7.f90: Test invalid, ambiguous interface.
	* gfortran.dg/interface_8.f90: Test warning for not-referenced-to
	ambiguous interfaces.
	* gfortran.dg/interface_1.f90: Change dg-error into a dg-warning.
	* gfortran.dg/array_initializer_2.f90: Add initializer array
	constructor test.

	PR fortran/30096
	* gfortran.dg/interface_9.f90: Test that host interfaces are
	not checked for ambiguity with the local version.

Added:
    trunk/gcc/testsuite/gfortran.dg/interface_4.f90
    trunk/gcc/testsuite/gfortran.dg/interface_5.f90
    trunk/gcc/testsuite/gfortran.dg/interface_6.f90
    trunk/gcc/testsuite/gfortran.dg/interface_7.f90
    trunk/gcc/testsuite/gfortran.dg/interface_8.f90
    trunk/gcc/testsuite/gfortran.dg/interface_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/array_initializer_2.f90
    trunk/gcc/testsuite/gfortran.dg/generic_7.f90
    trunk/gcc/testsuite/gfortran.dg/interface_1.f90

Comment 7 Paul Thomas 2006-12-21 15:05:48 UTC
Subject: Bug 30096

Author: pault
Date: Thu Dec 21 15:05:24 2006
New Revision: 120113

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120113
Log:
2006-12-21  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29975
	PR fortran/30068
	PR fortran/30096
	* interface.c (compare_type_rank_if): Reject invalid generic
	interfaces.
	(check_interface1): Give a warning for nonreferred to ambiguous
	interfaces.
	(check_sym_interfaces): Check whether an ambiguous interface is
	referred to.  Do not check host associated interfaces since these
	cannot be ambiguous with the local versions.
	(check_uop_interface, gfc_check_interfaces): Update call to
	check_interface1.
	* symbol.c (gfc_get_sym_tree, gfc_get_sym_tree): Allow adding
	unambiguous procedures to generic interfaces.
	* gfortran.h (symbol_attribute): Added use_only and
	ambiguous_interfaces.
	* module.c (load_need): Set the use_only flag, if needed.
	* resolve.c (resolve_fl_procedure): Warn for nonreferred
	interfaces.
	* expr.c (find_array_section): Fix initializer array contructor.


2006-12-21  Paul Thomas  <pault@gcc.gnu.org>
	    Tobias Burnus  <burnus@gcc.gnu.org>

	PR fortran/29975
	PR fortran/30068
	* gfortran.dg/interface_4.f90: Test adding procedure to generic
	interface.
	* gfortran.dg/interface_5.f90: Test warning for not-referenced-to
	ambiguous interfaces.
	* gfortran.dg/interface_6.f90: Test invalid, ambiguous interface.
	* gfortran.dg/interface_7.f90: Test invalid, ambiguous interface.
	* gfortran.dg/interface_8.f90: Test warning for not-referenced-to
	ambiguous interfaces.
	* gfortran.dg/interface_1.f90: Change dg-error into a dg-warning.
	* gfortran.dg/array_initializer_2.f90: Add initializer array
	constructor test.

	PR fortran/30096
	* gfortran.dg/interface_9.f90: Test that host interfaces are
	not checked for ambiguity with the local version.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_4.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_5.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_6.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_7.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_8.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_9.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/expr.c
    branches/gcc-4_2-branch/gcc/fortran/gfortran.h
    branches/gcc-4_2-branch/gcc/fortran/interface.c
    branches/gcc-4_2-branch/gcc/fortran/module.c
    branches/gcc-4_2-branch/gcc/fortran/resolve.c
    branches/gcc-4_2-branch/gcc/fortran/symbol.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/array_initializer_2.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/generic_7.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_1.f90

Comment 8 Paul Thomas 2006-12-21 15:07:48 UTC
Fixed on trunk and 4.2

Paul