public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/35824]  New: Overloading problems with derived type with allocatable array
@ 2008-04-04  9:19 everyo at gmx dot net
  2008-04-04 10:10 ` [Bug fortran/35824] " dominiq at lps dot ens dot fr
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: everyo at gmx dot net @ 2008-04-04  9:19 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-11-30  8:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-04  9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
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

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