]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix tab not ignored in print statement.
authorSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 2 Jan 2026 04:52:55 +0000 (20:52 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 2 Jan 2026 05:05:08 +0000 (21:05 -0800)
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.

gcc/fortran/io.cc
gcc/testsuite/gfortran.dg/pr101399_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr101399_2.f90 [new file with mode: 0644]

index 45cac5ee5727ae1fc9a86887074732832f68518a..55638c6599c9c6e10f59ea3aea448c872b8670b4 100644 (file)
@@ -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 (file)
index 0000000..14cf508
--- /dev/null
@@ -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 (file)
index 0000000..8fd2030
--- /dev/null
@@ -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