From: Steven G. Kargl Date: Fri, 2 Jan 2026 04:52:55 +0000 (-0800) Subject: Fortran: Fix tab not ignored in print statement. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81bef9ee8d8c18c4a40d4ef67ec9b310a8a326c9;p=thirdparty%2Fgcc.git 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 character following a 'print' statement; otherwise ignore the . gcc/testsuite/ChangeLog: * gfortran.dg/pr101399_1.f90: New test. * gfortran.dg/pr101399_2.f90: New test. --- diff --git a/gcc/fortran/io.cc b/gcc/fortran/io.cc index 45cac5ee572..55638c6599c 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*'. 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 00000000000..14cf50833ec --- /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 00000000000..8fd203057b2 --- /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