[gcc r16-6461] Fortran: Fix tab not ignored in print statement.

Jerry DeLisle jvdelisle@gcc.gnu.org
Fri Jan 2 05:36:57 GMT 2026


https://gcc.gnu.org/g:81bef9ee8d8c18c4a40d4ef67ec9b310a8a326c9

commit r16-6461-g81bef9ee8d8c18c4a40d4ef67ec9b310a8a326c9
Author: Steven G. Kargl <kargl@gcc.gnu.org>
Date:   Thu Jan 1 20:52:55 2026 -0800

    Fortran: Fix tab not ignored in print statement.
    
            PR fortran/101399
    
    gcc/fortran/ChangeLog:
    
            * io.cc (match_io): If the -Wtabs option is used, then Issue a
            warning for a <tab> character following a 'print' statement;
            otherwise ignore the <tab>.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/pr101399_1.f90: New test.
            * gfortran.dg/pr101399_2.f90: New test.

Diff:
---
 gcc/fortran/io.cc                        | 16 +++++++++++++++-
 gcc/testsuite/gfortran.dg/pr101399_1.f90 |  6 ++++++
 gcc/testsuite/gfortran.dg/pr101399_2.f90 |  6 ++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/io.cc b/gcc/fortran/io.cc
index 45cac5ee5727..55638c6599c9 100644
--- a/gcc/fortran/io.cc
+++ b/gcc/fortran/io.cc
@@ -4223,7 +4223,21 @@ match_io (io_kind k)
       if (gfc_current_form == FORM_FREE)
 	{
 	  char c = gfc_peek_ascii_char ();
-	  if (c != ' ' && c != '*' && c != '\'' && c != '"')
+
+	  /* Issue a warning for an invalid tab in 'print<tab>*'.  After
+	     the warning is issued, consume any other whitespace and check
+	     that the next char is an *, ', or ".  */
+	  if (c == '\t')
+	    {
+	      gfc_gobble_whitespace ();
+	      c = gfc_peek_ascii_char ();
+	      if (c != '*' && c != '\'' && c != '"')
+		{
+		  m = MATCH_NO;
+		  goto cleanup;
+		}
+	    }
+	  else if (c != ' ' && c != '*' && c != '\'' && c != '"')
 	    {
 	      m = MATCH_NO;
 	      goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr101399_1.f90 b/gcc/testsuite/gfortran.dg/pr101399_1.f90
new file mode 100644
index 000000000000..14cf50833ec5
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr101399_1.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! { dg-options "-O0" }
+program foo
+   ! The next statement has a tab between 'print' and '*'.
+   print	*, 'tab not always ignored'
+end program foo
diff --git a/gcc/testsuite/gfortran.dg/pr101399_2.f90 b/gcc/testsuite/gfortran.dg/pr101399_2.f90
new file mode 100644
index 000000000000..8fd203057b2d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr101399_2.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! { dg-options "-Wtabs" }
+program foo
+   ! The next statement has a tab between 'print' and '*'.
+   print	*, 'tab warning'  ! { dg-warning "Nonconforming tab" }
+end program foo


More information about the Gcc-cvs mailing list