User account creation filtered due to spam.

Bug 44917 - [OOP] Detect ambiguous specifics in a generic TBP interface
Summary: [OOP] Detect ambiguous specifics in a generic TBP interface
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: janus
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2010-07-12 08:52 UTC by janus
Modified: 2016-11-16 13:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2010-07-12 08:52:43 UTC
The current form of the test case dynamic_dispatch_1.f03 is illegal:


module m
  type :: t1
    integer :: i = 42
    procedure(make_real), pointer :: ptr
  contains
    procedure, pass :: real => make_real
    procedure, pass :: make_integer
    procedure, pass :: prod => i_m_j
    generic, public :: extract => real, make_integer
    generic, public :: base_extract => real, make_integer
  end type t1

  type, extends(t1) :: t2
    integer :: j = 99
  contains
    procedure, pass :: real => make_real2
    procedure, pass :: make_integer_2
    procedure, pass :: prod => i_m_j_2
    generic, public :: extract => real, make_integer_2
  end type t2
contains
  real function make_real (arg)
    class(t1), intent(in) :: arg
    make_real = real (arg%i)
  end function make_real

  real function make_real2 (arg)
    class(t2), intent(in) :: arg
    make_real2 = real (arg%j)
  end function make_real2

  integer function make_integer (arg, arg2)
    class(t1), intent(in) :: arg
    integer :: arg2
    make_integer = arg%i * arg2
  end function make_integer

  integer function make_integer_2 (arg, arg2)
    class(t2), intent(in) :: arg
    integer :: arg2
    make_integer_2 = arg%j * arg2
  end function make_integer_2

  integer function i_m_j (arg)
    class(t1), intent(in) :: arg
        i_m_j = arg%i
  end function i_m_j

  integer function i_m_j_2 (arg)
    class(t2), intent(in) :: arg
        i_m_j_2 = arg%j
  end function i_m_j_2
end module m


It is rejected by the NAG compiler with:

Error: dynamic_dispatch_1.f03, line 58: Ambiguous specific type-bound procedures MAKE_INTEGER_2 and MAKE_INTEGER for type-bound generic EXTRACT in type T2

gfortran currently fails to detect that.
Comment 1 janus 2010-07-12 08:59:31 UTC
Reduced version:

module m

  type :: t1
    integer :: i = 42
  contains
    procedure, pass :: make_integer
    generic, public :: extract => make_integer
  end type t1

  type, extends(t1) :: t2
    integer :: j = 99
  contains
    procedure, pass :: make_integer_2
    generic, public :: extract => make_integer_2
  end type t2

contains

  integer function make_integer (arg, arg2)
    class(t1), intent(in) :: arg
    integer :: arg2
    make_integer = arg%i * arg2
  end function make_integer

  integer function make_integer_2 (arg, arg2)
    class(t2), intent(in) :: arg
    integer :: arg2
    make_integer_2 = arg%j * arg2
  end function make_integer_2

end module m
 
Comment 2 janus 2010-07-12 09:02:49 UTC
Note that the ambiguity is detected if both specifics are already defined in the base class:

module m

  type :: t1
    integer :: i = 42
  contains
    procedure, pass :: make_integer
    procedure, pass :: make_integer_2
    generic, public :: extract => make_integer, make_integer_2
  end type t1

contains

  integer function make_integer (arg, arg2)
    class(t1), intent(in) :: arg
    integer :: arg2
    make_integer = arg%i * arg2
  end function make_integer

  integer function make_integer_2 (arg, arg2)
    class(t1), intent(in) :: arg
    integer :: arg2
    make_integer_2 = arg%i * arg2**2
  end function make_integer_2

end module m
 


    generic, public :: extract => make_integer, make_integer_2
                                 1
Error: 'make_integer' and 'make_integer_2' for GENERIC 'extract' at (1) are ambiguous
Comment 3 janus 2010-10-30 13:52:44 UTC
Author: janus
Date: Sat Oct 30 13:52:39 2010
New Revision: 166089

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166089
Log:
2010-10-30  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44917
	PR fortran/44926
	PR fortran/46196
	* interface.c (count_types_test): Symmetrize type check.
	(generic_correspondence): Ditto.

2010-10-30  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44917
	PR fortran/44926
	PR fortran/46196
	* gfortran.dg/typebound_generic_10.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_generic_10.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 janus 2010-10-30 13:55:27 UTC
Fixed with r166089. Closing.