public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "everyo at gmx dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/35824]  New: Overloading problems with derived type with allocatable array
Date: Fri, 04 Apr 2008 09:19:00 -0000	[thread overview]
Message-ID: <bug-35824-16016@http.gcc.gnu.org/bugzilla/> (raw)

I have a derived type with an allocatable array and have overloaded some
operations. Unfortunately assignments like a=-a don't work.

Code in the Module, where I definde the type:

  type alltype
     double precision :: a
     double precision,allocatable :: b(:)
  end type

      interface assignment(=)
      module procedure at_from_at
      end interface

      interface operator(-)
      module procedure  neg_at
      end interface

  contains

    subroutine at_from_at(b,a)
      type(alltype), intent(in) :: a
      type(alltype), intent(out) :: b

      b%a=a%a
      allocate(b%b(2))
      b%b=a%b

    end subroutine at_from_at

    function neg_at(a) result(b)
      type(alltype), intent(in) :: a
      type(alltype) :: b

      b%a=-a%a
      allocate(b%b(2))
      b%b=-a%b

    end function neg_at

The allocatable array has an dimension of 2 in this example...

Now the code:

 use typemodule

 type(alltype) t1,t2,t3

 allocate(t1%b(2))
 t1%a=0.5d0
 t1%b(1)=1d0
 t1%b(2)=2d0


 t2=-t1
 write(*,*) t2%a, t2%b

 t1=-t1
 write(*,*) t1%a, t1%b

Prints: 
 -0.50000000000000000      -1.00000000000000000       -2.0000000000000000
Segmentation fault

It seems that in the Module, the allocatated array of t1 doesn't get passed
properly in the t1=-t1 part. I have also seg. faults in situations like a=a+b
(where + is overloaded simiarly)

The same code works correctly with ifort.


-- 
           Summary: Overloading problems with derived type with allocatable
                    array
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: everyo at gmx dot net
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


             reply	other threads:[~2008-04-04  9:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-04  9:19 everyo at gmx dot net [this message]
2008-04-04 10:10 ` [Bug fortran/35824] " dominiq at lps dot ens dot fr
2008-04-04 14:15 ` burnus at gcc dot gnu dot org
2008-05-18 15:38 ` pault at gcc dot gnu dot org
2008-05-18 16:01 ` pault at gcc dot gnu dot org
2008-11-30  8:05 ` pault at gcc dot gnu dot org
2008-11-30  8:51 ` pault at gcc dot gnu dot 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-35824-16016@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).