[libgfortran] PR88052 - Format contravening f2008 constraint C1002 permitted

Message ID 11e90391-b886-60b3-dec4-80ad4819edbf@charter.net
State New
Headers show
Series
  • [libgfortran] PR88052 - Format contravening f2008 constraint C1002 permitted
Related show

Commit Message

Jerry Nov. 24, 2018, 8:40 p.m.
Hi all,

The attached patch adjusts the constraint of missing commas between
format specifiers by only allowing if std=legacy is given at compile time.

Several existing test cases are adjusted to be standard conforming.

Regression tested on x86-64-linux-gnu.

OK for trunk? (I will include the a change log for the testsuite.)

Jerry

2018-11-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libfortran/88052

* io/format.c (parse_format_list): Implement constraint which prohibits
   missing commas between format specifiers unless -std=legacy is given.

Patch

diff --git a/gcc/testsuite/gfortran.dg/comma_format_extension_4.f b/gcc/testsuite/gfortran.dg/comma_format_extension_4.f
index 30f07e803c5..1d018380f9c 100644
--- a/gcc/testsuite/gfortran.dg/comma_format_extension_4.f
+++ b/gcc/testsuite/gfortran.dg/comma_format_extension_4.f
@@ -1,7 +1,7 @@ 
 ! PR fortran/13257
-! Note the missing , before i1 in the format.
+! Note the missing , after i4 in the format.
 ! { dg-do run }
-! { dg-options "" }
+! { dg-options "-std=legacy" }
       character*6 c
       write (c,1001) 1
       if (c .ne. '    1 ') STOP 1
diff --git a/gcc/testsuite/gfortran.dg/dollar_edit_descriptor_2.f b/gcc/testsuite/gfortran.dg/dollar_edit_descriptor_2.f
index 437f4dfd811..de583f374dc 100644
--- a/gcc/testsuite/gfortran.dg/dollar_edit_descriptor_2.f
+++ b/gcc/testsuite/gfortran.dg/dollar_edit_descriptor_2.f
@@ -1,5 +1,5 @@ 
 ! { dg-do run }
-! { dg-options "-w" }
+! { dg-options "-w -std=legacy" }
 ! PR25545 internal file and dollar edit descriptor.
       program main
       character*20 line
diff --git a/gcc/testsuite/gfortran.dg/fmt_error_9.f b/gcc/testsuite/gfortran.dg/fmt_error_9.f
index 1d677509e37..23aee89208d 100644
--- a/gcc/testsuite/gfortran.dg/fmt_error_9.f
+++ b/gcc/testsuite/gfortran.dg/fmt_error_9.f
@@ -4,7 +4,7 @@ 
 ! Test case prepared by Jerry DeLisle <jvdelisle@gcc.gnu.org>
       character(len=25) :: str
       character(len=132) :: msg, line
-      str = '(1pd24.15e6)'
+      str = '(1pd24.15,e6)'
       line = "initial string"
       x = 555.25
       
@@ -19,11 +19,11 @@ 
       if (istat.ne.5006 .or. msg(1:15).ne."Positive width ") STOP 4
       if (x.ne.555.25) STOP 5
       
-      write (line,'(1pd24.15e11.3)') 1.0d0, 1.234
+      write (line,'(1pd24.15,e11.3)') 1.0d0, 1.234
       if (line.ne."   1.000000000000000D+00  1.234E+00") STOP 6
       
       str = '(1p2d24.15)'
       msg = "   1.000000000000000D+00   1.233999967575073D+00That's it!"
-      write (line,'(1p2d24.15a)') 1.0d0, 1.234, "That's it!"
+      write (line,'(1p2d24.15,a)') 1.0d0, 1.234, "That's it!"
       if (line.ne.msg) print *, msg
       end
diff --git a/gcc/testsuite/gfortran.dg/fmt_g0_5.f08 b/gcc/testsuite/gfortran.dg/fmt_g0_5.f08
index d2a97b1ac80..cafd90b94b5 100644
--- a/gcc/testsuite/gfortran.dg/fmt_g0_5.f08
+++ b/gcc/testsuite/gfortran.dg/fmt_g0_5.f08
@@ -6,13 +6,13 @@  program test_g0_special
 
     call check_all("(g10.3)", "(f10.3)")
     call check_all("(g10.3e3)", "(f10.3)")
-    call check_all("(spg10.3)", "(spf10.3)")
-    call check_all("(spg10.3e3)", "(spf10.3)")
+    call check_all("(sp,g10.3)", "(sp,f10.3)")
+    call check_all("(sp,g10.3e3)", "(sp,f10.3)")
     !print *, "-----------------------------------"
     call check_all("(g0)", "(f0.0)")
     call check_all("(g0.15)", "(f0.0)")
-    call check_all("(spg0)", "(spf0.0)")
-    call check_all("(spg0.15)", "(spf0.0)")
+    call check_all("(sp,g0)", "(sp,f0.0)")
+    call check_all("(sp,g0.15)", "(sp,f0.0)")
 contains
     subroutine check_all(fmt1, fmt2)
         character(len=*), intent(in) :: fmt1, fmt2
diff --git a/gcc/testsuite/gfortran.dg/fmt_t_2.f90 b/gcc/testsuite/gfortran.dg/fmt_t_2.f90
index 01647655de6..56414c54bfb 100644
--- a/gcc/testsuite/gfortran.dg/fmt_t_2.f90
+++ b/gcc/testsuite/gfortran.dg/fmt_t_2.f90
@@ -12,7 +12,7 @@ 
       read (11, '(a040,t1,040a)', end = 999)  foost1 , foost2
       if (foost1.ne.foost2) STOP 1
 
-      read (11, '(a032,t2,a032t3,a032)', end = 999)  foost1 , foost2, foost3
+      read (11, '(a032,t2,a032,t3,a032)', end = 999)  foost1 , foost2, foost3
       if (foost1(1:32).ne."123456789 123456789 123456789   ") STOP 2
       if (foost2(1:32).ne."23456789 123456789 123456789    ") STOP 3
       if (foost3(1:32).ne."3456789 123456789 123456789     ") STOP 4
diff --git a/libgfortran/io/format.c b/libgfortran/io/format.c
index f5d3158d21d..5ad57bef316 100644
--- a/libgfortran/io/format.c
+++ b/libgfortran/io/format.c
@@ -46,7 +46,8 @@  static const char posint_required[] = "Positive width required in format",
   bad_string[] = "Unterminated character constant in format",
   bad_hollerith[] = "Hollerith constant extends past the end of the format",
   reversion_error[] = "Exhausted data descriptors in format",
-  zero_width[] = "Zero width in format descriptor";
+  zero_width[] = "Zero width in format descriptor",
+  comma_missing[] = "Missing comma between descriptors";
 
 /* The following routines support caching format data from parsed format strings
    into a hash table.  This avoids repeatedly parsing duplicate format strings
@@ -1168,8 +1169,10 @@  parse_format_list (st_parameter_dt *dtp, bool *seen_dd)
       goto finished;
 
     default:
-      /* Assume a missing comma, this is a GNU extension */
-      goto format_item_1;
+      /* Assume a missing comma with -std=legacy, GNU extension. */
+      if (compile_options.warn_std == 0)
+	goto format_item_1;
+      format_error (dtp, tail, comma_missing);
     }
 
   /* Optional comma is a weird between state where we've just finished