]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/89103 (Allow blank format items in format strings)
authorJim MacArthur <jim.macarthur@codethink.co.uk>
Wed, 19 Jun 2019 03:02:21 +0000 (03:02 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Wed, 19 Jun 2019 03:02:21 +0000 (03:02 +0000)
2019-06-19  Jim MacArthur  <jim.macarthur@codethink.co.uk>
    Mark Eggleston  <mark.eggleston@codethink.com>

PR fortran/89103
* gfortran.texi: Add -fdec-blank-format-item
* invoke.texi: Add option to list of options.
* invoke.texi: Add to section on Commas in FORMAT specifications.
* io.c (check_format): At FMT_RPAREN goto finished if
-fdec-blank-format-item otherwise set error string.
* lang.opt: Add new option.
* options.c (set_dec_flags): Add SET_BITFLAG for
flag_dec_format_defaults.

* gfortran.dg/dec_format_empty_item_1.f: New test.
* gfortran.dg/dec_format_empty_item_2.f: New test.
* gfortran.dg/dec_format_empty_item_3.f: New test.

Co-Authored-By: Mark Eggleston <mark.eggleston@codethink.com>
From-SVN: r272467

gcc/fortran/ChangeLog
gcc/fortran/gfortran.texi
gcc/fortran/invoke.texi
gcc/fortran/io.c
gcc/fortran/lang.opt
gcc/fortran/options.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f [new file with mode: 0644]
gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f [new file with mode: 0644]
gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f [new file with mode: 0644]

index 32d961ade9601a83fb6517019dd510bae3c4aade..289be5b6c81a7090d6dde1a514c9c7cd2ebd4e2b 100644 (file)
@@ -1,3 +1,16 @@
+2019-06-19  Jim MacArthur  <jim.macarthur@codethink.co.uk>
+           Mark Eggleston  <mark.eggleston@codethink.com>
+       
+       PR fortran/89103
+       * gfortran.texi: Add -fdec-blank-format-item
+       * invoke.texi: Add option to list of options.
+       * invoke.texi: Add to section on Commas in FORMAT specifications.
+       * io.c (check_format): At FMT_RPAREN goto finished if
+       -fdec-blank-format-item otherwise set error string.
+       * lang.opt: Add new option.
+       * options.c (set_dec_flags): Add SET_BITFLAG for
+       flag_dec_format_defaults.
+
 2019-06-18  Julian Brown  <julian@codesourcery.com>
 
        PR fortran/90921
index 57461e0e42fa41e2c722b7008c5b6660d236ba54..c887e7d1a4251bf56c6e40dc43f69f0dcadd5bd6 100644 (file)
@@ -1761,11 +1761,16 @@ When omitted, the count is implicitly assumed to be one.
 
 To support legacy codes, GNU Fortran allows the comma separator
 to be omitted immediately before and after character string edit
-descriptors in @code{FORMAT} statements.
+descriptors in @code{FORMAT} statements.  A comma with no following format
+decriptor is permited if the @option{-fdec-blank-format-item} is given on
+the command line. This is considered non-conforming code and is
+discouraged.
 
 @smallexample
        PRINT 10, 2, 3
 10     FORMAT ('FOO='I1' BAR='I2)
+       print 20, 5, 6
+20     FORMAT (I3, I3,)
 @end smallexample
 
 
index 2e2cb5b2728c02f3c71802a7a41888be210f8d89..2b08ac4de22fd600f59a8775513e51f00317546f 100644 (file)
@@ -119,10 +119,10 @@ by type.  Explanations are in the following sections.
 @gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol
 -fd-lines-as-comments -fdec -fdec-structure -fdec-intrinsic-ints @gol
 -fdec-static -fdec-math -fdec-include -fdec-format-defaults @gol
--fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 -fdefault-real-10 @gol
--fdefault-real-16 -fdollar-ok -ffixed-line-length-@var{n} @gol
--ffixed-line-length-none -fpad-source -ffree-form @gol
--ffree-line-length-@var{n} -ffree-line-length-none @gol
+-fdec-blank-format-item -fdefault-double-8 -fdefault-integer-8 @gol
+-fdefault-real-8 -fdefault-real-10 -fdefault-real-16 -fdollar-ok @gol
+-ffixed-line-length-@var{n} -ffixed-line-length-none -fpad-source @gol
+-ffree-form -ffree-line-length-@var{n} -ffree-line-length-none @gol
 -fimplicit-none -finteger-4-integer-8 -fmax-identifier-length @gol
 -fmodule-private -ffixed-form -fno-range-check -fopenacc -fopenmp @gol
 -freal-4-real-10 -freal-4-real-16 -freal-4-real-8 -freal-8-real-10 @gol
@@ -289,6 +289,11 @@ be on a single line and can use line continuations.
 Enable format specifiers F, G and I to be used without width specifiers,
 default widths will be used instead.
 
+@item -fdec-blank-format-item
+@opindex @code{fdec-blank-format-item}
+Enable a blank format item at the end of a format specification i.e. nothing
+following the final comma.
+
 @item -fdollar-ok
 @opindex @code{fdollar-ok}
 @cindex @code{$}
index 776cdbf98ceef75cff94b268033ea5ca685ac408..425c2b86899f791233b2f5bc5119b7c7172b2a50 100644 (file)
@@ -762,6 +762,15 @@ format_item_1:
       error = unexpected_end;
       goto syntax;
 
+    case FMT_RPAREN:
+      if (flag_dec_blank_format_item)
+       goto finished;
+      else
+       {
+         error = G_("Missing item in format string at %L");
+         goto syntax;
+       }
+
     default:
       error = unexpected_element;
       goto syntax;
index 93ea3d3977be49d3d8bf504e8985cfc64c4633f6..88674cb5dc7a7aebce3774d8e031a980870a8fdd 100644 (file)
@@ -444,6 +444,10 @@ fdec
 Fortran Var(flag_dec)
 Enable all DEC language extensions.
 
+fdec-blank-format-item
+Fortran Var(flag_dec_blank_format_item)
+Enable the use of blank format items in format strings.
+
 fdec-include
 Fortran Var(flag_dec_include)
 Enable legacy parsing of INCLUDE as statement.
index 4f91486e977f2e3707bd8f3a969397db703b1b25..3bc79ef9b45b269c038334ee527095250ff7189c 100644 (file)
@@ -75,6 +75,7 @@ set_dec_flags (int value)
   SET_BITFLAG (flag_dec_math, value, value);
   SET_BITFLAG (flag_dec_include, value, value);
   SET_BITFLAG (flag_dec_format_defaults, value, value);
+  SET_BITFLAG (flag_dec_blank_format_item, value, value);
 }
 
 /* Finalize DEC flags.  */
index 116795fe7a0c8dfe2ab14f7cafcb0ec6f01f28ca..8255d9e37517634000179d6dadb799607a7fa054 100644 (file)
@@ -1,3 +1,11 @@
+2019-06-19  Jim MacArthur  <jim.macarthur@codethink.co.uk>
+           Mark Eggleston  <mark.eggleston@codethink.com>
+
+       PR fortran/89103
+       * gfortran.dg/dec_format_empty_item_1.f: New test.
+       * gfortran.dg/dec_format_empty_item_2.f: New test.
+       * gfortran.dg/dec_format_empty_item_3.f: New test. 
+
 2019-06-19  Kugan Vivekanandarajah  <kugan.vivekanandarajah@linaro.org>
 
        * gcc.target/aarch64/pr88834.c: Move from here...
diff --git a/gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f b/gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f
new file mode 100644 (file)
index 0000000..ed27c18
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do run }
+! { dg-options "-fdec" }
+!
+! Test blank/empty format items in format string
+!
+! Test case contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
+!
+        PROGRAM blank_format_items
+          INTEGER A/0/
+
+          OPEN(1, status="scratch")
+          WRITE(1, 10) 100
+          REWIND(1)
+          READ(1, 10) A
+          IF (a.NE.100) STOP 1
+          PRINT 10, A
+10        FORMAT( I5,)
+        END
diff --git a/gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f b/gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f
new file mode 100644 (file)
index 0000000..2793cb1
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do run }
+! { dg-options "-fdec-blank-format-item" }
+!
+! Test blank/empty format items in format string
+!
+! Test case contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
+!
+        PROGRAM blank_format_items
+          INTEGER A/0/
+
+          OPEN(1, status="scratch")
+          WRITE(1, 10) 100
+          REWIND(1)
+          READ(1, 10) A
+          IF (a.NE.100) STOP 1
+          PRINT 10, A
+10        FORMAT( I5,)
+        END
diff --git a/gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f b/gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f
new file mode 100644 (file)
index 0000000..dbccd67
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! { dg-options "-fdec -fno-dec-blank-format-item" }
+!
+! Test blank/empty format items in format string
+!
+! Test case contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
+!
+        PROGRAM blank_format_items
+          INTEGER A/0/
+
+          OPEN(1, status="scratch")
+          WRITE(1, 10) 100 ! { dg-error "FORMAT label 10 at" }
+          REWIND(1)
+          READ(1, 10) A ! { dg-error "FORMAT label 10 at" }
+          IF (a.NE.100) STOP 1
+          PRINT 10, A ! { dg-error "FORMAT label 10 at" }
+ 10       FORMAT( I5,) ! { dg-error "Missing item" }
+        END