public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bdavis at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/28039] Warn when ignoring extra characters in the format specification Date: Wed, 30 Dec 2009 04:26:00 -0000 [thread overview] Message-ID: <20091230042549.13817.qmail@sourceware.org> (raw) In-Reply-To: <bug-28039-1719@http.gcc.gnu.org/bugzilla/> ------- 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.burnus@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
next prev parent reply other threads:[~2009-12-30 4:26 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-06-15 11:10 [Bug fortran/28039] New: " tobias dot burnus at physik dot fu-berlin dot de 2006-06-20 11:04 ` [Bug fortran/28039] " fxcoudert at gcc dot gnu dot org 2009-08-22 23:21 ` bdavis at gcc dot gnu dot org 2009-08-23 2:20 ` bdavis at gcc dot gnu dot org 2009-08-23 2:27 ` bdavis at gcc dot gnu dot org 2009-08-24 8:53 ` burnus at gcc dot gnu dot org 2009-08-26 23:10 ` hp at gcc dot gnu dot org 2009-08-27 6:29 ` burnus at gcc dot gnu dot org 2009-08-27 12:00 ` burnus at gcc dot gnu dot org 2009-08-27 12:11 ` burnus at gcc dot gnu dot org 2009-12-30 4:26 ` bdavis at gcc dot gnu dot org [this message] 2009-12-30 5:23 ` bdavis at gcc dot gnu dot org 2010-04-09 2:03 ` jvdelisle at gcc dot gnu dot org 2010-04-09 3:25 ` jvdelisle at gcc dot gnu dot org 2010-04-24 3:05 ` jvdelisle at gcc dot gnu dot org 2010-04-24 3:05 ` jvdelisle at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20091230042549.13817.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).