------- Comment #10 from bdavis at gcc dot gnu dot org 2009-12-30 04:25 ------- let's give this a try:
Index: gcc/gcc/testsuite/gfortran.dg/fmt_with_extra.f =================================================================== --- gcc/gcc/testsuite/gfortran.dg/fmt_with_extra.f (revision 155511) +++ gcc/gcc/testsuite/gfortran.dg/fmt_with_extra.f (working copy) @@ -4,5 +4,25 @@ implicit none real :: r r = 1.0 - write(*,'(a),f)') 'Hello', r ! { dg-warning "Extraneous characters in format at" "PR28039" { xfail *-*-* } } + write(*,'(a),f)') 'Hello', r ! { dg-warning "Extraneous characters in format at" } end +! Below routine was also submitted by tobias.bur...@physik.fu-berlin.de +! It showed up some problems with the initial implementation of this +! feature. +! This routine should compile without complaint or warning. + SUBROUTINE rw_inp() + CHARACTER(len=100) :: line + integer :: i5 + character(100), parameter :: subchapter = + & '(79("-"),/,5("-")," ",A,/,79("-"),/)' + i5 = 1 + + READ(*,FMT="(4x,a)") line + 7182 FORMAT (a3) + 7130 FORMAT (i3) + + WRITE (6,'(//'' icorr is not correctly transferred. icorr='',i5) + & ') 42 + + write(*,subchapter) 'test' + END SUBROUTINE rw_inp Index: gcc/gcc/fortran/io.c =================================================================== --- gcc/gcc/fortran/io.c (revision 155511) +++ gcc/gcc/fortran/io.c (working copy) @@ -850,11 +850,11 @@ if (u != FMT_POSINT) { format_locus.nextc += format_string_pos; - gfc_error_now ("Positive width required in format " + gfc_error ("Positive width required in format " "specifier %s at %L", token_to_string (t), &format_locus); saved_token = u; - goto finished; + goto fail; } u = format_lex (); @@ -866,11 +866,11 @@ format_locus.nextc += format_string_pos; if (gfc_option.warn_std != 0) { - gfc_error_now ("Period required in format " + gfc_error ("Period required in format " "specifier %s at %L", token_to_string (t), &format_locus); saved_token = u; - goto finished; + goto fail; } else gfc_warning ("Period required in format " @@ -970,11 +970,11 @@ gfc_warning ("The H format specifier at %L is" " a Fortran 95 deleted feature", &format_locus); } - if (mode == MODE_STRING) { format_string += value; format_length -= value; + format_string_pos += repeat; } else { @@ -1152,6 +1152,8 @@ static gfc_try check_format_string (gfc_expr *e, bool is_input) { + gfc_try rv; + int i; if (!e || e->ts.type != BT_CHARACTER || e->expr_type != EXPR_CONSTANT) return SUCCESS; @@ -1162,8 +1164,20 @@ format string that has been calculated, but that's probably not worth the effort. */ format_locus = e->where; - - return check_format (is_input); + rv = check_format (is_input); + /* check for extraneous characters at the end of an otherwise valid format + string, like '(A10,I3)F5' + start at the end and move back to the last character processed, + spaces are OK */ + if (rv == SUCCESS && e->value.character.length > format_string_pos) + for (i=e->value.character.length-1;i>format_string_pos-1;i--) + if (e->value.character.string[i] != ' ') + { + format_locus.nextc += format_length + 1; + gfc_warning ("Extraneous characters in format at %L", &format_locus); + break; + } + return rv; } will submit an official patch after doing regtesting against a clean tree. since we are 'stabilizing' for 4.5, it might be a while for this is committed so i am posting it here so the work is not lost. --bud -- bdavis at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |ASSIGNED Last reconfirmed|2009-08-22 23:21:18 |2009-12-30 04:25:49 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28039