This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: gfortran 4.6 crashes with a type-bound procedure that overloads .LT.
- From: Janus Weil <janus at gcc dot gnu dot org>
- To: Mark Rashid <mmrashid at ucdavis dot edu>
- Cc: fortran <fortran at gcc dot gnu dot org>
- Date: Thu, 7 Oct 2010 10:40:38 +0200
- Subject: Re: gfortran 4.6 crashes with a type-bound procedure that overloads .LT.
- References: <1286401597.22978.97.camel@skyliner>
> I have run into erratic behavior trying to compile a module that defines
> a derived type with a component that is, in turn, another derived type
> that has a type-bound relational operator (.LT.). ?Depending on the
> specifics, I sometimes get a compiler crash and sometimes successful
> completion, but wrong code. ?Near-minimal code that produces a crash is
> copied below.
>
> Module DEF1 compiles OK. ?But subsequently trying to compile module MESH
> produces:
>
> f951: ?internal compiler error: in gfc_add_component_ref, at
> fortran/class.c:77
>
> The problem seems to be the line
>
> LST = (A%PT .LT. B%PT)
>
> in module MESH, which invokes the overloaded .LT. defined in module
> DEF1.
Note: This problem seems to be specific to type-bound operators, since
it goes away when I transform your operator ".LT." into a generic TBP
"LT" like this:
MODULE DEF1
TYPE :: DAT
INTEGER :: NN
REAL :: XYZ(3)
CONTAINS
PROCEDURE :: LESS_THAN
GENERIC :: LT => LESS_THAN
END TYPE DAT
CONTAINS
FUNCTION LESS_THAN(A, B)
CLASS (DAT), INTENT (IN) :: A, B
LOGICAL :: LESS_THAN
LESS_THAN = (A%NN .LT. B%NN)
RETURN
END FUNCTION LESS_THAN
END MODULE DEF1
!=============================================================
MODULE MESH
USE DEF1
TYPE NODE
INTEGER :: KEY
CLASS (DAT), POINTER :: PT
CONTAINS
PROCEDURE :: LST
GENERIC :: LT => LST
END TYPE NODE
CONTAINS
FUNCTION LST (A, B)
CLASS (NODE), INTENT (IN) :: A, B
LOGICAL :: LST
IF (A%KEY .GT. 0 .AND. B%KEY .GT. 0) THEN
LST = (A%KEY .LT. B%KEY)
ELSE
LST = A%PT%LT(B%PT)
END IF
RETURN
END FUNCTION LST
END MODULE MESH
Cheers,
Janus