Bug 55297 - [4.8 Regression] [OOP] type-bound operator clashes with abstract interface
Summary: [4.8 Regression] [OOP] type-bound operator clashes with abstract interface
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-11-12 23:17 UTC by Damian Rouson
Modified: 2012-11-16 18:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-11-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Damian Rouson 2012-11-12 23:17:06 UTC
$ cat athlete.f90
module athlete_module
  type athlete
  contains
    procedure :: negative
    generic :: operator(-) => negative
  end type
  abstract interface 
    integer function sum_interface(this)
      import athlete
      class(athlete) this
    end function
  end interface
contains
  integer function negative(this)
    class(athlete) ,intent(in) :: this
  end function
end module
$ gfortran-mp-4.7 -c athlete.f90
$ gfortran-mp-4.8 -c athlete.f90
athlete.f90:5.29:

    generic :: operator(-) => negative
                             1
Error: Entity 'negative' at (1) is already present in the interface
wlan-clients-2916:gnu rouson$ gfortran-mp-4.8 --version
GNU Fortran (MacPorts gcc48 4.8-20121021_0) 4.8.0 20121021 (experimental)
Comment 1 Dominique d'Humieres 2012-11-12 23:46:10 UTC
Revision 188914 (2012-06-24) does not give error; revision 189336 (2012-07-06) does.
Comment 2 Tobias Burnus 2012-11-13 11:19:24 UTC
Seems to be due to http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189022
for PR fortran/41951 and PR fortran/49591.

In the resolve.c's resolve_typebound_intrinsic_op:

11546             if (gfc_check_new_interface (derived->ns->op[op], target_proc,
11547                                          p->where) == FAILURE)

Here target_proc->name == "negative" and target_proc->ns->proc_name->name
== "athlete_module"

The symbol (i.e. derived type) is resolved twice: Once for the "module athlete_module" (= gfc_current_ns->proc_name) and then again for the abstract interface procedure "sum_interface" (= gfc_current_ns->proc_name).

In either case, one has derived->ns->proc_name->name == "athlete_module", which causes the symbol be added twice added to the same namespace.

The question is whether it should be fixed by adding
   if (derived->ns != gfc_current_ns)
     return;
Or using "gfc_current_ns" instead of "derived->ns". Or what's the most appropriate fix.
Comment 3 janus 2012-11-16 11:41:50 UTC
(In reply to comment #2)
> The question is whether it should be fixed by adding
>    if (derived->ns != gfc_current_ns)
>      return;

Yes, something along this line seems like the appropriate fix to me. In particular I would propose the following (which does fix the test case):


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 193552)
+++ gcc/fortran/resolve.c	(working copy)
@@ -11540,7 +11540,7 @@ resolve_typebound_intrinsic_op (gfc_symbol* derive
 
       /* Add target to non-typebound operator list.  */
       if (!target->specific->deferred && !derived->attr.use_assoc
-	  && p->access != ACCESS_PRIVATE)
+	  && p->access != ACCESS_PRIVATE && derived->ns == gfc_current_ns)
 	{
 	  gfc_interface *head, *intr;
 	  if (gfc_check_new_interface (derived->ns->op[op], target_proc,


Will commit as obvious after regtesting ...
Comment 4 janus 2012-11-16 17:02:07 UTC
Author: janus
Date: Fri Nov 16 17:02:02 2012
New Revision: 193568

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

	PR fortran/55297
	* resolve.c (resolve_typebound_intrinsic_op): Only add typebound
	operators to the operator list in the namespace of the derived type.

2012-11-16  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/55297
	* gfortran.dg/typebound_operator_18.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_operator_18.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 janus 2012-11-16 18:17:28 UTC
Fixed with r193568. Closing.