User account creation filtered due to spam.

Bug 54832 - [4.8 Regression] [OOP] Type-bound operator not picked up with RESULT variable
Summary: [4.8 Regression] [OOP] Type-bound operator not picked up with RESULT variable
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-10-06 09:56 UTC by janus
Modified: 2012-10-06 14:07 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-10-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2012-10-06 09:56:37 UTC
Reported by Damian Rouson at:

http://gcc.gnu.org/ml/fortran/2012-10/msg00032.html


Test case:

module integrand_module

  type ,abstract :: integrand
  contains
    procedure(t_interface), deferred :: t
    procedure(assign_interface), deferred :: assign
    procedure(times_interface), deferred :: times
    generic :: operator(*) => times
    generic :: assignment(=) => assign
  end type

  abstract interface
    function t_interface(this) result(dState_dt)
      import :: integrand
      class(integrand) ,intent(in)  :: this
      class(integrand) ,allocatable :: dState_dt
    end function
    function times_interface(lhs,rhs)
      import :: integrand
      class(integrand) ,intent(in)  :: lhs
      class(integrand) ,allocatable :: times_interface
      real, intent(in)  :: rhs
    end function
    subroutine assign_interface(lhs,rhs)
      import :: integrand
      class(integrand) ,intent(in)    :: rhs
      class(integrand) ,intent(inout) :: lhs
    end subroutine
  end interface

contains
  subroutine integrate(model,dt)
    class(integrand) :: model
    real dt
    model = model%t()*dt
  end subroutine
end module 


While 4.7 compiles it cleanly, 4.8 gives:

    model = model%t()*dt
            1
Error: Operands of binary numeric operator '*' at (1) are CLASS(integrand)/REAL(4)
Comment 1 Dominique d'Humieres 2012-10-06 10:42:05 UTC
The ICE appeared between revisions 190356, 2012-08-13 (OK) and 190442, 2012-08-16 (ICE), and was replaced by an error between revisions 191969, 2012-10-02 (ICE) and 192074, 2012-10-04 (error).
Comment 2 janus 2012-10-06 11:10:11 UTC
(In reply to comment #1)
> The ICE appeared between revisions 190356, 2012-08-13 (OK) and 190442,
> 2012-08-16 (ICE)

Here I'm not completely sure about which one is the culprit ...


> and was replaced by an error between revisions 191969,
> 2012-10-02 (ICE) and 192074, 2012-10-04 (error).

... but this is probably due to:

http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192005
Comment 3 janus 2012-10-06 11:17:46 UTC
The problem was apparently that the 'class_ok' attribute was not propagated properly. The following patch fixes it for me:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 192004)
+++ gcc/fortran/resolve.c	(working copy)
@@ -12009,6 +12009,7 @@ resolve_fl_derived0 (gfc_symbol *sym)
 		  c->attr.pointer = ifc->result->attr.pointer;
 		  c->attr.dimension = ifc->result->attr.dimension;
 		  c->as = gfc_copy_array_spec (ifc->result->as);
+		  c->attr.class_ok = ifc->result->attr.class_ok;
 		}
 	      else
 		{   
@@ -12017,6 +12018,7 @@ resolve_fl_derived0 (gfc_symbol *sym)
 		  c->attr.pointer = ifc->attr.pointer;
 		  c->attr.dimension = ifc->attr.dimension;
 		  c->as = gfc_copy_array_spec (ifc->as);
+		  c->attr.class_ok = ifc->attr.class_ok;
 		}
 	      c->ts.interface = ifc;
 	      c->attr.function = ifc->attr.function;
@@ -12028,7 +12030,6 @@ resolve_fl_derived0 (gfc_symbol *sym)
 	      c->attr.recursive = ifc->attr.recursive;
 	      c->attr.always_explicit = ifc->attr.always_explicit;
 	      c->attr.ext_attr |= ifc->attr.ext_attr;
-	      c->attr.class_ok = ifc->attr.class_ok;
 	      /* Replace symbols in array spec.  */
 	      if (c->as)
 		{
Comment 4 janus 2012-10-06 14:03:14 UTC
Author: janus
Date: Sat Oct  6 14:03:08 2012
New Revision: 192160

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

	PR fortran/54832
	* resolve.c (resolve_fl_derived0): Correctly copy the 'class_ok'
	attribute for proc-ptr components with RESULT variable.

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

	PR fortran/54832
	* gfortran.dg/typebound_operator_17.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_operator_17.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 janus 2012-10-06 14:07:37 UTC
Fixed with r192160. Closing.