Bug 43388 - [F2008][OOP] ALLOCATE with MOLD=
Summary: [F2008][OOP] ALLOCATE with MOLD=
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords:
Depends on:
Blocks: 44541
  Show dependency treegraph
 
Reported: 2010-03-16 12:45 UTC by Tobias Burnus
Modified: 2010-06-15 18:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-13 02:46:52


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-03-16 12:45:43 UTC
F2003 supported
  ALLOCATE( A, SOURCE=B)
where the dynamic type of B determined the dynamic type of A plus where the values where copied from B to A.

Fortran 2008 now also offers MOLD= where only the type is used, but no data is copied.

Fortran 2008 draft FDIS: ftp://ftp.nag.co.uk/sc22wg5/N1801-N1850/N1814.pdf

R626 allocate-stmt is ALLOCATE ( [ type-spec :: ] allocation-list [, alloc-opt-list ] )
R627 alloc-opt  is  ERRMSG = errmsg-variable
                or  MOLD = source-expr
                or  SOURCE = source-expr
                or  STAT = stat-variable

"If MOLD= appears and source-expr is a variable, its value need not be defined."


And in the introduction one finds the following:

"A structure constructor can omit the value for an allocatable component. SOURCE= in an ALLOCATE statement can give an array variable the bounds as well as the value of an expression. MOLD= in an ALLOCATE statement can give a polymorphic variable the shape, type, and type parameters of an expression without copying the value."
Comment 1 Tobias Burnus 2010-03-16 13:58:45 UTC
Found the right spot in the standard (well, actually Bill Long did):

"if source-expr is specified, each allocate-object is allocated with the dynamic type and type parameter values of source-expr; otherwise, each allocate-object is allocated with its dynamic type the same as its declared type."
Comment 2 janus 2010-06-13 02:46:51 UTC
I'll assign this to myself (working on a patch ...)
Comment 3 janus 2010-06-15 18:35:19 UTC
Subject: Bug 43388

Author: janus
Date: Tue Jun 15 18:33:58 2010
New Revision: 160801

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160801
Log:
2010-06-15  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/43388
	* gfortran.h (gfc_expr): Add new member 'mold'.
	* match.c (gfc_match_allocate): Implement the MOLD tag.
	* resolve.c (resolve_allocate_expr): Ditto.
	* trans-stmt.c (gfc_trans_allocate): Ditto.


2010-06-15  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/43388
	* gfortran.dg/allocate_alloc_opt_8.f90: New.
	* gfortran.dg/allocate_alloc_opt_9.f90: New.
	* gfortran.dg/allocate_alloc_opt_10.f90: New.
	* gfortran.dg/class_allocate_2.f03: Modified an error message.

Added:
    trunk/gcc/testsuite/gfortran.dg/allocate_alloc_opt_10.f90
    trunk/gcc/testsuite/gfortran.dg/allocate_alloc_opt_8.f90
    trunk/gcc/testsuite/gfortran.dg/allocate_alloc_opt_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_allocate_2.f03

Comment 4 janus 2010-06-15 18:42:39 UTC
Fixed with r160801. Remaining problems are tracked by PR 44541.