public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR32987 - Allow TAB in FORMAT statements as extension  and warn with -std=f*
@ 2007-08-04 17:37 Tobias Burnus
  2007-08-04 18:08 ` Jerry DeLisle
  0 siblings, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2007-08-04 17:37 UTC (permalink / raw)
  To: 'fortran@gcc.gnu.org', gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1497 bytes --]

:ADDPATCH fortran:

In FORMAT statements, standard Fortran only allow tabs ('\t') in string
literals. However, all other compiler I checked allow it: ifort, g95,
NAG f95, sunf95, openf95. Except of ifort (with the option "-stand f95")
none of the compilers even print a compile-time warning.

gfortran currently accepts tabs quietly at compile time, but gives a
run-time error.

Given that all other compilers allow it, I would suggest to allow it as
well - and follow ifort by giving a warning with -std=f95/f2003.
(Actually, I have chosen to give a gfc_warning instead of an gfc_error
to save myself from several levels of error propagation :-)

Note, however, that Steve disagrees (see PR for full quote):

"A tab is not a legal substitution for a space character." [...]
"Here's a patch that permits gfortran to accept your INVALID code."
(His patch is the same as the libgfortran part of my patch; he continues
then:)
"[...] I will activity oppose application of this patch by others."

Reasoning by Steve:

"gfortran has been around for a long time now and this is the first
report of the tab-in-format runtime error. gfortran should complain
loudly that the code is invalid."


While I still think accepting it with a compile-time warning is enough,
I strongly believe that there should be in any case a COMPILE-TIME
diagnostic whatever we decide about accepting or rejecting it at run time.


Build and regression tested on x86_64-unknown-linux-gnu.


Let the discussion start ...

Tobias

[-- Attachment #2: tab.diff --]
[-- Type: text/x-patch, Size: 1687 bytes --]

2007-08-04  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32987
	* io.c (next_char_not_space): Warn if '\t' are used in
	format specifications.

2007-08-04  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32987
	* io/format.c (): Treat '\t' as ' ' in format specifications.

2007-08-04  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32987
	* gfortran.dg/fmt_tab.f90: New.

Index: gcc/fortran/io.c
===================================================================
--- gcc/fortran/io.c	(revision 127204)
+++ gcc/fortran/io.c	(working copy)
@@ -181,6 +181,8 @@ next_char_not_space (void)
   do
     {
       c = next_char (0);
+      if (c == '\t' && !(gfc_option.allow_std & GFC_STD_GNU))
+	gfc_warning ("Extension: Tab character in format at %C");
     }
   while (gfc_is_whitespace (c));
   return c;
Index: libgfortran/io/format.c
===================================================================
--- libgfortran/io/format.c	(revision 127204)
+++ libgfortran/io/format.c	(working copy)
@@ -92,7 +92,7 @@ next_char (format_data *fmt, int literal
       fmt->format_string_len--;
       c = toupper (*fmt->format_string++);
     }
-  while (c == ' ' && !literal);
+  while ((c == ' ' || c == '\t') && !literal);
 
   return c;
 }
Index: gcc/testsuite/gfortran.dg/fmt_tab.f90
===================================================================
--- gcc/testsuite/gfortran.dg/fmt_tab.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/fmt_tab.f90	(revision 0)
@@ -0,0 +1,7 @@
+! { dg-do run }
+! { dg-options "-std=f2003" }
+! PR fortran/32987
+      program TestFormat
+        write (*, 10)
+ 10     format ('Hello ',	'bug!') ! { dg-warning "Extension: Tab character in format" }
+      end

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-08-09 22:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-04 17:37 [Patch, Fortran] PR32987 - Allow TAB in FORMAT statements as extension and warn with -std=f* Tobias Burnus
2007-08-04 18:08 ` Jerry DeLisle
2007-08-04 20:30   ` Tobias Burnus
2007-08-09 21:41     ` FX Coudert
2007-08-09 22:05       ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).