public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mailling-lists-bd at posteo dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/100813] New: Function of array of pointers to abstract class returning an array
Date: Fri, 28 May 2021 13:34:49 +0000	[thread overview]
Message-ID: <bug-100813-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100813

            Bug ID: 100813
           Summary: Function of array of pointers to abstract class
                    returning an array
           Product: gcc
           Version: 10.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mailling-lists-bd at posteo dot de
  Target Milestone: ---

Hello, 

I was trying to write a function that takes an array of pointers to an abstract
class as argument, and that returns an array with a shape determined by a
member of the mentioned abstract class.  The following example segfaults with
gfortran 10.3 on Opensuse: 

module baseClass
  implicit none

  type, abstract, public :: base
     integer, allocatable :: i(:)
   contains
     procedure(sub), deferred, pass :: mysub
  end type base

  abstract interface
     subroutine sub(bb) 
       import :: base
       class(base), intent(in) :: bb
     end subroutine sub
  end interface

  type, public :: baseWrap
     class(base), pointer :: p
  end type baseWrap

  public :: operate_on_baseWrap

contains

  function operate_on_baseWrap(wrapped) result(res)
    class(baseWrap), intent(in) :: wrapped(:)

    integer :: i, tmp
    integer, dimension(size(wrapped(1)%p%i)) :: res

    do i=1, size(wrapped)
       call wrapped(i)%p%mysub
    end do

    res = 0
  end function operate_on_baseWrap

end module baseClass


module childClass
  use baseClass
  implicit none

  type, extends(base), public :: child1
   contains
     procedure, pass :: mysub => sub_child1
  end type child1

contains

  subroutine sub_child1(bb)
    class(child1), intent(in) :: bb

    print *, 'Do something', bb%i
  end subroutine sub_child1

end module childClass


program test
  use baseClass
  use childClass
  implicit none

  type(baseWrap), allocatable :: wrapper(:)

  type(child1), allocatable, target :: c(:)

  integer :: i

  integer, allocatable :: tmp(:)

  allocate(wrapper(3))
  allocate(c(3))

  do i=1, 3
     allocate(c(i)%i(3))
     c(i)%i = i
     wrapper(i)%p => c(i)
  end do

  allocate(tmp(size(wrapper(1)%p%i)))
  tmp = operate_on_baseWrap(wrapper)
end program test

             reply	other threads:[~2021-05-28 13:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 13:34 mailling-lists-bd at posteo dot de [this message]
2021-05-31  8:38 ` [Bug fortran/100813] Function of array of pointers to abstract class returning an array since r6-202-gf3b0bb7a560be0f0 marxin at gcc dot gnu.org
2021-05-31 10:53 ` dominiq at lps dot ens.fr
2022-04-21 18:25 ` mikael at gcc dot gnu.org
2022-04-22 12:31 ` marxin at gcc dot gnu.org
2024-06-12  7:23 ` vehre at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-100813-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).