The attached patch reverts a change I made for pr65456 which caused this regression and adds a check for quotes farther down in the function. This avoids treating a '!' in a string as a comment and wiping the rest of the line.
I found the added code is needed because an interposing quote was falling through and being changed into an empty space at around line 1393. (I do not recall the history of why that space is being done) The patch also updates test case continuation_13.f90. I found another compiler I use for comparison interprets the continuation differently and is inserting a space that is not there. So the format at line 800 is handled differently now with gfortran and the line 900 format example is added to test both cases with and without a space just before the continuation. I think now gfortran has this right, but I do not rule out that I am missing some obscure rule. This begs a question about the space character substituted near line 1393 in scanner.c, but at the moment I do not think it is related. I have also added a test for the the original problem reported in this PR to avoid future repeating of the problem. I will provide a Changelog entry for the testsuite changes. Regression tested on x86-64-linux. OK to trunk? followed to 5.1? Regards, Jerry 2015-05-14 Jerry DeLisle <jvdeli...@gcc.gnu.org> PR fortran/65903 * io.c (format_lex): Change to NONSTRING when checking for possible doubled quote. * scanner.c (gfc_next_char_literal): Revert change from 64506, add a check for quotes, and return.
Index: gcc/fortran/io.c =================================================================== --- gcc/fortran/io.c (revision 223105) +++ gcc/fortran/io.c (working copy) @@ -385,7 +385,7 @@ format_lex (void) if (c == delim) { - c = next_char (INSTRING_NOWARN); + c = next_char (NONSTRING); if (c == '\0') { Index: gcc/fortran/scanner.c =================================================================== --- gcc/fortran/scanner.c (revision 223105) +++ gcc/fortran/scanner.c (working copy) @@ -1272,21 +1272,11 @@ restart: are still in a string and we are looking for a possible doubled quote and we end up here. See PR64506. */ - if (in_string) + if (in_string && c != '\n') { gfc_current_locus = old_loc; - - if (c == '!') - { - skip_comment_line (); - goto restart; - } - - if (c != '\n') - { - c = '&'; - goto done; - } + c = '&'; + goto done; } if (c != '!' && c != '\n') @@ -1392,6 +1382,8 @@ restart: "Missing %<&%> in continued character " "constant at %C"); } + else if (!in_string && (c == '\'' || c == '"')) + goto done; /* Both !$omp and !$ -fopenmp continuation lines have & on the continuation line only optionally. */ else if (openmp_flag || openacc_flag || openmp_cond_flag) Index: gcc/testsuite/gfortran.dg/continuation_13.f90 =================================================================== --- gcc/testsuite/gfortran.dg/continuation_13.f90 (revision 223105) +++ gcc/testsuite/gfortran.dg/continuation_13.f90 (working copy) @@ -19,6 +19,8 @@ character(25) :: astring ) 800 format('This is actually ok.'& !comment ' end' ) +900 format('This is actually ok.' & !comment + ' end' ) write(astring,100) if (astring.ne."This format is OK.") call abort write(astring,200) @@ -34,6 +36,8 @@ if (astring.ne."This format now works.'") call abo write(astring,700) if (astring.ne."This format now works.'") call abort write(astring,800) +if (astring.ne."This is actually ok.' end") call abort +write(astring,900) if (astring.ne."This is actually ok. end") call abort end
! { dg-do run } ! { dg-options "-std=gnu" } ! character(20) :: astring 100 format ("& notblank !") 200 format ("& !") write(astring,100) if (astring.ne."& notblank !") call abort !print *, astring write(astring,200) if (astring.ne."& !") call abort !print *, astring end