------- Comment #8 from dominiq at lps dot ens dot fr  2009-12-04 21:37 -------
With the patch in comment #7 the tests in pr41829 and the following ones
segfault at runtime.

!--------------------------------

module m
  type :: t1
    integer :: i = 42
  contains
    procedure, pass :: prod => i_m_j
  end type t1
  type, extends(t1) :: t2
    integer :: j = 99
  end type t2
contains
  integer function i_m_j (arg)
    class(t1), intent(in) :: arg
    select type (arg)
      type is (t1)
        i_m_j = 0
      class is (t2)
        i_m_j = 1
      class default
        print *, "should not be here"
    end select
  end function i_m_j
end module m

  use m
  class(t1), pointer :: a
  type(t1), target :: b
  type(t2), target :: c
  integer :: itmp
  a => b
  itmp = a%prod()
  print *, itmp
  a => c
  itmp = a%prod()
  print *, itmp
end

!--------------------------------

module m

  type :: null_type
  end type

  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
  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


  use m
  class(t1), pointer :: a !=> NULL()
  type(t1), target :: b
  type(t2), target :: c
  a => b
  print *, a%i,a%real(), a%prod(), a%extract (2)
  a => c
  print *, a%i,a%real(), a%prod(), a%extract (3)
end


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42274

Reply via email to