Commit 8e8dc060 by Daniel Kraft Committed by Daniel Kraft

re PR fortran/45776 (Full implementation of variable definition contexts (and related checks))

2010-09-25  Daniel Kraft  <d@domob.eu>

	PR fortran/45776
	* gfortran.h (struct gfc_dt): New member `dt_io_kind'.
	* io.c (resolve_tag): F2008 check for NEWUNIT and variable
	definition checks for NEWUNIT, IOSTAT, SIZE and IOMSG.
	(gfc_free_dt): Correctly handle freeing of `dt_io_kind' and
	`extra_comma' with changed semantics.
	(gfc_resolve_dt): Check variable definitions.
	(match_io_element): Remove INTENT and PURE checks here and
	initialize code->ext.dt member.
	(match_io): Set dt->dt_io_kind.
	(gfc_resolve_inquire): Check variable definition for all tags
	except UNIT, FILE and ID.
	* resolve.c (resolve_transfer): Variable definition check.

2010-09-25  Daniel Kraft  <d@domob.eu>

	PR fortran/45776
	* gfortran.dg/io_constraints_6.f03: New test.
	* gfortran.dg/io_constraints_7.f03: New test.
	* gfortran.dg/newunit_2.f90: New test.

From-SVN: r164619
parent c21136ee
2010-09-25 Daniel Kraft <d@domob.eu>
PR fortran/45776
* gfortran.h (struct gfc_dt): New member `dt_io_kind'.
* io.c (resolve_tag): F2008 check for NEWUNIT and variable
definition checks for NEWUNIT, IOSTAT, SIZE and IOMSG.
(gfc_free_dt): Correctly handle freeing of `dt_io_kind' and
`extra_comma' with changed semantics.
(gfc_resolve_dt): Check variable definitions.
(match_io_element): Remove INTENT and PURE checks here and
initialize code->ext.dt member.
(match_io): Set dt->dt_io_kind.
(gfc_resolve_inquire): Check variable definition for all tags
except UNIT, FILE and ID.
* resolve.c (resolve_transfer): Variable definition check.
2010-09-25 Tobias Burnus <burnus@net-b.de> 2010-09-25 Tobias Burnus <burnus@net-b.de>
* interface.c (gfc_match_end_interface): Constify char pointer * interface.c (gfc_match_end_interface): Constify char pointer
......
...@@ -2000,7 +2000,7 @@ typedef struct ...@@ -2000,7 +2000,7 @@ typedef struct
{ {
gfc_expr *io_unit, *format_expr, *rec, *advance, *iostat, *size, *iomsg, gfc_expr *io_unit, *format_expr, *rec, *advance, *iostat, *size, *iomsg,
*id, *pos, *asynchronous, *blank, *decimal, *delim, *pad, *round, *id, *pos, *asynchronous, *blank, *decimal, *delim, *pad, *round,
*sign, *extra_comma; *sign, *extra_comma, *dt_io_kind;
gfc_symbol *namelist; gfc_symbol *namelist;
/* A format_label of `format_asterisk' indicates the "*" format */ /* A format_label of `format_asterisk' indicates the "*" format */
......
...@@ -7916,6 +7916,13 @@ resolve_transfer (gfc_code *code) ...@@ -7916,6 +7916,13 @@ resolve_transfer (gfc_code *code)
&& exp->expr_type != EXPR_FUNCTION)) && exp->expr_type != EXPR_FUNCTION))
return; return;
/* If we are reading, the variable will be changed. Note that
code->ext.dt may be NULL if the TRANSFER is related to
an INQUIRE statement -- but in this case, we are not reading, either. */
if (code->ext.dt && code->ext.dt->dt_io_kind->value.iokind == M_READ
&& gfc_check_vardef_context (exp, false, _("item in READ")) == FAILURE)
return;
sym = exp->symtree->n.sym; sym = exp->symtree->n.sym;
ts = &sym->ts; ts = &sym->ts;
......
2010-09-25 Daniel Kraft <d@domob.eu>
PR fortran/45776
* gfortran.dg/io_constraints_6.f03: New test.
* gfortran.dg/io_constraints_7.f03: New test.
* gfortran.dg/newunit_2.f90: New test.
2010-09-24 Steven G. Kargl < kargl@gcc.gnu.org> 2010-09-24 Steven G. Kargl < kargl@gcc.gnu.org>
* testsuite/gfortran.dg/operator_c1202.f90: New test. * testsuite/gfortran.dg/operator_c1202.f90: New test.
......
! { dg-do compile }
! PR fortran/45776
! Variable definition context checks related to IO.
! Contributed by Daniel Kraft, d@domob.eu.
module m
implicit none
integer, protected :: a
character(len=128), protected :: str
end module m
program main
use :: m
integer, parameter :: b = 42
integer :: x
character(len=128) :: myStr
namelist /definable/ x, myStr
namelist /undefinable/ x, a
! These are invalid.
read (myStr, *) a ! { dg-error "variable definition context" }
read (myStr, *) x, b ! { dg-error "variable definition context" }
write (str, *) 5 ! { dg-error "variable definition context" }
read (*, nml=undefinable) ! { dg-error "contains the symbol 'a' which may not" }
! These are ok.
read (str, *) x
write (myStr, *) a
write (myStr, *) b
print *, a, b
write (*, nml=undefinable)
read (*, nml=definable)
write (*, nml=definable)
end program main
! { dg-final { cleanup-modules "m" } }
! { dg-do compile }
! PR fortran/45776
! Variable definition context checks related to IO.
! Contributed by Daniel Kraft, d@domob.eu.
module m
implicit none
integer, protected :: a
character(len=128), protected :: msg
end module m
program main
use :: m
integer :: x
logical :: bool
write (*, iostat=a) 42 ! { dg-error "variable definition context" }
write (*, iomsg=msg) 42 ! { dg-error "variable definition context" }
read (*, '(I2)', advance='no', size=a) x ! { dg-error "variable definition context" }
! These are ok.
inquire (unit=a)
inquire (file=msg, id=a, pending=bool)
inquire (file=msg)
! These not, but list is not extensive.
inquire (unit=1, number=a) ! { dg-error "variable definition context" }
inquire (unit=1, encoding=msg) ! { dg-error "variable definition context" }
inquire (unit=1, formatted=msg) ! { dg-error "variable definition context" }
open (newunit=a, file="foo") ! { dg-error "variable definition context" }
close (unit=a)
end program main
! { dg-final { cleanup-modules "m" } }
! { dg-do compile }
! { dg-options "-std=f95" }
! PR40008 F2008: Add NEWUNIT= for OPEN statement
! Check for rejection with pre-F2008 standard.
! Contributed by Daniel Kraft, d@domob.eu.
program main
character(len=25) :: str
integer(1) :: myunit
open (newunit=myunit, file="some_file") ! { dg-error "Fortran 2008" }
close (unit=myunit)
end program main
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment