From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13217 invoked by alias); 18 Nov 2011 15:54:09 -0000 Received: (qmail 13207 invoked by uid 22791); 18 Nov 2011 15:54:08 -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, 18 Nov 2011 15:53:53 +0000 From: "kargl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51208] [OOP] ALLOCATE with SOURCE= or MOLD=: Diagnose if variable occurs twice Date: Fri, 18 Nov 2011 16:10: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: accepts-invalid, diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl 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: CC 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: 2011-11/txt/msg01898.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51208 kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kargl at gcc dot gnu.org --- Comment #1 from kargl at gcc dot gnu.org 2011-11-18 15:53:51 UTC --- (In reply to comment #0) > In ALLOCATE, one gets a diagnosis if one uses: > > integer, allocatable :: i > allocate(i, stat=i) > end > > Namely: > allocate(i, stat=i) > 1 > Error: Stat-variable at (1) shall not be ALLOCATEd within > the same ALLOCATE statement The above error is easy to produce, because gfortran only has to check if an alloc-object is used as a stat-variable. > > However, for SOURCE= and MOLD= it does not work: > > type t > integer :: i = 4 > end type t > class(t), allocatable :: x, y > > allocate(t :: y) > allocate(x, mold=x) ! Not diagnosed > allocate(x, source=x) ! Not diagnosed Doing a check here requires a walk of the mold-expr and the source-expr, which is of course much more work (unless gfortran already has a helper function to check if a variable is used within an expression). Here's a simple example where walking source-expr may find the use of the alloc-object: module bar real, allocatable :: x(:) contains function f(a) real f real :: a(:) f = sum(a) end function end module bar program foo use bar allocate(x(2), source=f(x)) print *, x end program foo ! !program foo ! use bar ! allocate(x(2), source=f([1., 2.])) ! print *, x !end program foo and here's a more complicated example. module bar real, allocatable :: x(:) contains function f(a) real f real :: a f = sum(a * x) ! x used un-allocated? end function end module bar program foo use bar allocate(x(2), source=f(2.)) print *, x end program foo