This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [fortran, 4.5] Implement errmsg for [de]allocate
On Wed, Dec 03, 2008 at 08:28:48PM +0100, Tobias Burnus wrote:
> Hi Steve,
>
> Steve Kargl wrote:
> > 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.
> >
> Somehow it does not work if one additionally requests a STAT= variable:
>
> deallocate(x, stat=i, errmsg=err)
> 1
> Error: Syntax error in DEALLOCATE statement at (1)
>
> (Ditto for: errmsg=..., stat=...)
I may have misinterpreted the 'or' in the BNF:
R623 allocate-stmt is ALLOCATE ( [ type-spec :: ] allocation-list
[, alloc-opt-list ] )
R624 alloc-opt is STAT = stat-variable
or ERRMSG = errmsg-variable
or SOURCE = source-expr
alloc-opt-list is not defined but C630 suggests that a combination of
the alloc-opts can appear.
C630 (R624) No alloc-opt shall appear more than once in a given alloc-opt-list.
It's easy to fix. I'll work out it this weekend.
> Additionally: Can we add a -Wsurprising which checks for the presence of
> STAT= when ERRMSG= is given? NAG f95 prints:
>
> Warning: hfjgf.f90, line 6: ERRMSG= is useless without STAT=
>
> > deallocate(x, x, errmsg=err)
> > print *, err
> There are several issues:
> a) "deallocate(x, x)" is invalid, which can be compile-time diagnosable
> (as e.g. ifort does), better place it in two lines
OK. gfortran doesn't currently catch at compile time.
REMOVE:kargl[125] gfc4x -o z b.f90
REMOVE:kargl[126] ./z
At line 4 of file b.f90
Fortran runtime error: Attempt to DEALLOCATE unallocated 'i'
REMOVE:kargl[127] cat b.f90
program a
integer, allocatable :: i(:)
allocate(i(4))
deallocate(i, i)
end program a
> b) "print *, err" is invalid - it always prints uninitialized value (in
> case of success). In case of a failure, it does not print anything as
> DEALLOCATE aborts
The code in the email was a quick hack to show the current error
message. The testcase is completely legal.
> "If an error condition occurs during execution of an ALLOCATE statement
> that does not contain the STAT= specifier, execution of the program is
> terminated."
Hmmm, that's going to complicate the trans-*c code. In fact, this
pretty makes errmsg useless without stat, so your -Wsurprising
should probably be a plain old warning.
>
> I will review the patch itself later.
>
Wait for an update. I have a 5 hour flight home
tomorrow night.
--
Steve