From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18436 invoked by alias); 13 Jan 2012 22:18:48 -0000 Received: (qmail 18428 invoked by uid 22791); 13 Jan 2012 22:18:47 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Jan 2012 22:18:35 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51634] [OOP] ICE with polymorphic operators Date: Fri, 13 Jan 2012 22:21:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg01570.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51634 --- Comment #2 from Tobias Burnus 2012-01-13 22:17:53 UTC --- (In reply to comment #1) > Fixed on trunk as long as explicit allocations are inserted, as below. > I will raise a separate PR for the lack of automatic allocate on assign for > class objects with derived type components. The test case now works since the commit of PR 48351 (and thus I closed PR 51733). The following allocates of comment 1 are still needed, though - otherwise the code is invalid: function multiply(lhs,rhs) allocate(multiply) program main allocate (g%f(2), source = [1.0, 2.0]) * * * Unfortunately, the original program still fails. New test case; produces with ifort 12.1: 6.000000 12.00000 18.00000 24.00000 30.00000 36.00000 Fails with gfortran at: Invalid free() / delete / delete[] / realloc() at 0x4C28C3E: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x401BD0: MAIN__ (test.f90:34) The "free" issue only occurs for: fireworks = fireworks + fireworks * dt It works with fireworks = fireworks + fireworks or with fireworks = fireworks * dt I am not sure why it fails, but the following looks a bit odd: struct soop_stars D.1952; class.8._data = (struct soop_stars *) &D.1952; ... if (class.8.position.data != 0B) __builtin_free ((void *) class.8.position.data); Shouldn't that be: "class.8._data.position.data" (not the "_data")? module soop_stars_class implicit none type soop_stars real, dimension(:), allocatable :: position,velocity contains procedure :: total procedure :: product generic :: operator(+) => total generic :: operator(*) => product end type contains type(soop_stars) function product(lhs,rhs) class(soop_stars) ,intent(in) :: lhs real ,intent(in) :: rhs product%position = lhs%position*rhs product%velocity = lhs%velocity*rhs end function type(soop_stars) function total(lhs,rhs) class(soop_stars) ,intent(in) :: lhs,rhs total%position = lhs%position + rhs%position total%velocity = lhs%velocity + rhs%velocity end function end module program main use soop_stars_class ,only : soop_stars implicit none type(soop_stars) :: fireworks real :: dt fireworks%position = [1,2,3] fireworks%velocity = [4,5,6] dt = 5 fireworks = fireworks + fireworks*dt print *, fireworks%position print *, fireworks%velocity end program