Bug 44549 - [OOP][F2008] Type-bound procedure: bogus error from list after PROCEDURE
Summary: [OOP][F2008] Type-bound procedure: bogus error from list after PROCEDURE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-15 19:53 UTC by Dominique d'Humieres
Modified: 2010-06-16 12:56 UTC (History)
2 users (show)

See Also:
Host: x86_64-apple-darwin10.3.0
Target: x86_64-apple-darwin10.3.0
Build: x86_64-apple-darwin10.3.0
Known to work:
Known to fail:
Last reconfirmed: 2010-06-15 21:05:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2010-06-15 19:53:29 UTC
After the fix for pr40117 with r160646, the following code (borrowed from somewhere)

MODULE rational_numbers
  IMPLICIT NONE
  PRIVATE
  TYPE,PUBLIC :: rational
    PRIVATE
    INTEGER n,d

    CONTAINS
    ! ordinary type-bound procedure
    PROCEDURE :: real => rat_to_real
    ! specific type-bound procedures for generic support
    PROCEDURE,PRIVATE :: rat_asgn_i, rat_plus_rat, rat_plus_i
    PROCEDURE,PRIVATE,PASS(b) :: i_plus_rat
    ! generic type-bound procedures
    GENERIC :: ASSIGNMENT(=) => rat_asgn_i
    GENERIC :: OPERATOR(+) => rat_plus_rat, rat_plus_i, i_plus_rat
  END TYPE
  CONTAINS
    ELEMENTAL REAL FUNCTION rat_to_real(this) RESULT(r)
      CLASS(rational),INTENT(IN) :: this
      r = REAL(this%n)/this%d
    END FUNCTION
    
    ELEMENTAL SUBROUTINE rat_asgn_i(a,b)
      CLASS(rational),INTENT(OUT) :: a
      INTEGER,INTENT(IN) :: b
      a%n = b
      a%d = 1
    END SUBROUTINE

    ELEMENTAL TYPE(rational) FUNCTION rat_plus_i(a,b) RESULT(r)
      CLASS(rational),INTENT(IN) :: a
      INTEGER,INTENT(IN) :: b
      r%n = a%n + b*a%d
      r%d = a%d
    END FUNCTION
    
    ELEMENTAL TYPE(rational) FUNCTION i_plus_rat(a,b) RESULT(r)
      INTEGER,INTENT(IN) :: a
      CLASS(rational),INTENT(IN) :: b
      r%n = b%n + a*b%d
      r%d = b%d
    END FUNCTION
    
    ELEMENTAL TYPE(rational) FUNCTION rat_plus_rat(a,b) RESULT(r)
      CLASS(rational),INTENT(IN) :: a,b
      r%n = a%n*b%d + b%n*a%d
      r%d = a%d*b%d
    END FUNCTION
END

gives the following bogus error:


class_test.f90:31.48:

    ELEMENTAL TYPE(rational) FUNCTION rat_plus_i(a,b) RESULT(r)
                                                1
Error: Assignment operator interface at (1) must be a SUBROUTINE

and gives an ICE when compiled with -std=f2003


class_test.f90:12.49:

    PROCEDURE,PRIVATE :: rat_asgn_i, rat_plus_rat, rat_plus_i
                                                 1
Error: Fortran 2008: PROCEDURE list at (1)
class_test.f90:16.29:

    GENERIC :: OPERATOR(+) => rat_plus_rat, rat_plus_i, i_plus_rat
                             1
Error: Undefined specific binding 'rat_plus_i' as target of GENERIC '+' at (1)
f951: internal compiler error: Segmentation fault
Comment 1 janus 2010-06-15 21:05:39 UTC
Dominique, thanks for reporting this. I can confirm the error you're seeing and I already see what's wrong: In 'match_procedure_in_type' the handling of the gfc_typebound_proc structures is not correct (each procedure in the list gets the same structure).

Will post a patch shortly.
Comment 2 janus 2010-06-16 12:55:22 UTC
Subject: Bug 44549

Author: janus
Date: Wed Jun 16 12:54:54 2010
New Revision: 160834

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

	PR fortran/44549
	* gfortran.h (gfc_get_typebound_proc): Modified Prototype.
	* decl.c (match_procedure_in_type): Give a unique gfc_typebound_proc
	structure to each procedure in a procedure list.
	* module.c (mio_typebound_proc): Add NULL argument to
	'gfc_get_typebound_proc'.
	* symbol.c (gfc_get_typebound_proc): Add a new argument, which is used
	to initialize the new structure.


2010-06-16  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44549
	* gfortran.dg/typebound_proc_16.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/typebound_proc_16.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 janus 2010-06-16 12:56:36 UTC
Fixed with r160834. Closing.