[fortran, 4.5] Implement errmsg for [de]allocate

Steve Kargl sgk@troutmask.apl.washington.edu
Wed Dec 3 19:06:00 GMT 2008


The attached patch implements the F2003 feature of ERRMSG= in
the [DE]ALLOCATE statements.  The current patch makes use of
the infrastructure for STAT= to determine if a failure occurs.
The STAT= code simply counts the number of failures.  For example,

  program a
  character(len=70) err
  real, allocatable :: x(:)
  allocate(x(4))
  deallocate(x, x, errmsg=err)
  print *, err
  end program a

yields

REMOVE:kargl[113] gfc4x -o z b.f90
REMOVE:kargl[114] ./z
 Attempt to deallocate an unallocated object                           
   
If STAT code is changed to accumulate the sum of the argument positions
that fail during [de]allocation, then a better error message could be
generated.  For example,  for the above program one could have

 Attempt to deallocate an unallocated object at position 2

Note, the F2003 standard does not specify what the error message must
contain.  So, I see no benefit of changing the STAT code.

Regression tested of i686-*-freebsd.

2008-12-02  Steven G. Kargl  <kargls@comcast.net>

	* gfortran.dg/errmsg_1.f90: New test

2008-12-02  Steven G. Kargl  <kargls@comcast.net>
	    Paul Thomas  <pault@gcc.gnu.org>

	* fortran/trans-stmt.c (gfc_trans_allocate):  Initialize trees to
	silence gcc.  Add code to generate ERRMSG.
	(gfc_trans_deallocate): Ditto.  Remove stale comments.
	* fortran/resolve.c:  Move error condition from here ...
	* fortran/match.c (gfc_match_allocate, gfc_match_deallocate)): ... to
	here.  Add parsing of ERRMSG argument to [DE]ALLOCATE.

-- 
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: errmsg.diff
Type: text/x-diff
Size: 12286 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20081203/50183548/attachment.bin>


More information about the Fortran mailing list