Bug 49591 - [OOP] Multiple identical specific procedures in type-bound operator not detected
[OOP] Multiple identical specific procedures in type-bound operator not detected
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.7.0
: P3 normal
: ---
Assigned To: janus
: accepts-invalid
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-06-30 12:52 UTC by Tobias Burnus
Modified: 2012-06-27 17:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-08-04 16:49:55


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-06-30 12:52:52 UTC
The first code ("module M1") is accepted without any error.
Expected: Diagnose that the generic operator (+) has two ambiguous specific bindings, one to myadd_t the other to myadd_x.

Ditto for the second code ("M2"), which is also currently accepted.



  module M1
    type T
      integer x
    contains
      procedure :: MyAdd_t => myadd
      generic :: operator(+) => myAdd_t
    end type T
    type X
      real q
    contains
      procedure, pass(b) :: MyAdd_x => myadd
      generic :: operator(+) => myAdd_x
    end type X
  contains
    integer function MyAdd ( A, B )
      class(t), intent(in) :: A
      class(x), intent(in) :: B
      myadd = a%x + b%q
    end function MyAdd
  end module

  module M2
    interface operator(+)
      procedure MyAdd
    end interface
    type T
      integer x
    contains
      procedure :: MyAdd_t => myadd
      generic :: operator(+) => myAdd_t
    end type T
  contains
    integer function MyAdd ( A, B )
      class(t), intent(in) :: A
      real, intent(in) :: B
      myadd = a%x + b
    end function MyAdd
  end module
Comment 1 janus 2011-08-04 16:49:55 UTC
Adjusting title. The problem really only applies to (type-bound) *operators*, right?
Comment 2 Tobias Burnus 2011-08-04 19:36:03 UTC
I think I found the place where this example came from, though at that point it probably was not yet on the server:
  http://www.j3-fortran.org/doc/meeting/195/11-214.txt
Comment 3 Tobias Burnus 2011-08-04 19:39:32 UTC
(In reply to comment #1)
> Adjusting title. The problem really only applies to (type-bound) *operators*,
> right?

No idea. The example is, but I don't know whether other generics are properly checked for ambiguity or not.
Comment 4 janus 2011-08-04 20:05:28 UTC
(In reply to comment #3)
> (In reply to comment #1)
> > Adjusting title. The problem really only applies to (type-bound) *operators*,
> > right?
> 
> No idea. The example is, but I don't know whether other generics are properly
> checked for ambiguity or not.

Well, I think they should be (but one should re-check this).


Anyway the second example (M2) is constructed in such a way that it only applies to operators: One bound to a type, the other not. For generics one can distinguish whether the type-bound version is called or not.

The first example (M1), on the other hand, could also be constructed with two type-bound generics of same name, bound to different types. But then again, the pass-argument can be determined uniquely, so there is no ambiguity about which type-bound generic should be called.

For generics the situation is different due to the different syntax of invocation (both operands could be the pass-argument).


When both versions are bound to the same specific procedure, one could as well take a "so what?" POV, because it doesn't matter which version you call.

For me, the more problematic case is the one where both operators are bound to different specifics, but with the same interface. There you have the same ambiguity as to which one to call, but the results will differ depending on your decision. This case we probably also fail to reject (haven't checked, though).
Comment 5 janus 2012-06-25 19:06:32 UTC
Note that this PR is basically a duplicate of PR 41951, which contains a test case analogous to the M2 case.
Comment 6 janus 2012-06-27 17:38:11 UTC
Author: janus
Date: Wed Jun 27 17:38:00 2012
New Revision: 189022

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189022
Log:
2012-06-27  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41951
	PR fortran/49591
	* interface.c (check_new_interface): Rename, add 'loc' argument,
	make non-static.
	(gfc_add_interface): Rename 'check_new_interface'
	* gfortran.h (gfc_check_new_interface): Add prototype.
	* resolve.c (resolve_typebound_intrinsic_op): Add typebound operator
	targets to non-typebound operator list.


2012-06-27  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41951
	PR fortran/49591
	* gfortran.dg/typebound_operator_16.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_operator_16.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 janus 2012-06-27 17:51:10 UTC
Fixed with r189022. Closing.