aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io
diff options
context:
space:
mode:
authorTilo Schwarz <tilo@tilo-schwarz.de>2013-03-20 07:45:49 +0000
committerTobias Burnus <burnus@gcc.gnu.org>2013-03-20 08:45:49 +0100
commit09c7dc636d0f407c4184b33e97928c3e2545130b (patch)
tree0744b6d570842d8431a17b50679a66226389d6f5 /libgfortran/io
parenta192015dbab317517c463c5ed1ce03f3df22cbbe (diff)
downloadgcc-09c7dc636d0f407c4184b33e97928c3e2545130b.zip
gcc-09c7dc636d0f407c4184b33e97928c3e2545130b.tar.gz
gcc-09c7dc636d0f407c4184b33e97928c3e2545130b.tar.bz2
re PR libfortran/48618 (Negative unit number in OPEN(...) is sometimes allowed)
2013-03-20 Tilo Schwarz <tilo@tilo-schwarz.de> PR libfortran/48618 * io/open.c (st_open): Raise error for unit number < 0 only if unit number does not exist already. 2013-03-20 Tilo Schwarz <tilo@tilo-schwarz.de> PR libfortran/48618 * gfortran.dg/open_negative_unit_1.f90: New. From-SVN: r196805
Diffstat (limited to 'libgfortran/io')
-rw-r--r--libgfortran/io/open.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index d9cfde8..19fab1d 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -818,10 +818,6 @@ st_open (st_parameter_open *opp)
flags.convert = conv;
- if (!(opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT) && opp->common.unit < 0)
- generate_error (&opp->common, LIBERROR_BAD_OPTION,
- "Bad unit number in OPEN statement");
-
if (flags.position != POSITION_UNSPECIFIED
&& flags.access == ACCESS_DIRECT)
generate_error (&opp->common, LIBERROR_BAD_OPTION,
@@ -848,8 +844,16 @@ st_open (st_parameter_open *opp)
{
if ((opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT))
opp->common.unit = get_unique_unit_number(opp);
+ else if (opp->common.unit < 0)
+ {
+ u = find_unit (opp->common.unit);
+ if (u == NULL) /* Negative unit and no NEWUNIT-created unit found. */
+ generate_error (&opp->common, LIBERROR_BAD_OPTION,
+ "Bad unit number in OPEN statement");
+ }
- u = find_or_create_unit (opp->common.unit);
+ if (u == NULL)
+ u = find_or_create_unit (opp->common.unit);
if (u->s == NULL)
{
u = new_unit (opp, u, &flags);