When the following program (truncbug.f) is compiled with gfortran 4.3.2: SUBROUTINE ERRMSG(N,STRING,LST) CHARACTER*72 TEXT(2) DATA (TEXT(I),I=1,2)/ X'MUST BE "CALL SIMEPS(EPS)"', X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T XHE CALL.'/ END This warning message results: truncbug.f:4.72: X'MUST BE "CALL SIMEPS(EPS)"', 1 Warning: initialization string truncated to match variable at (1) This is two lines before the line that the string truncation occurs on. Ideally, gfortran should put the (1) mark at the character in the string where the truncation occurs.
Suggested patch: http://gcc.gnu.org/ml/fortran/2010-05/msg00116.html
Excellent! The new warning is far more understandable than the old. X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T 1 Warning: Initialization string starting at (1) was truncated after 72 characters to match the variable If it's difficult to place the error marker at the location the string was truncated, would it be easy to list the number of characters in the initialization string, so that one would not have to count characters to determine how many characters need to be removed, or how much larger to make the variable? Example: X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T 1 Warning: Initialization string of 73 characters starting at (1) was truncated after 72 characters to match the variable
That's easily doable. Alternative patch for data.c below gives: $ gfortran-svn pr38404.f pr38404.f:5.7: X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T 1 Warning: Initialization string starting at (1) was truncated to fit the variable (73/72) (Modified the message to be similar to many other actual-size/expected-size outputs) Index: data.c =================================================================== --- data.c (revision 159348) +++ data.c (working copy) @@ -154,9 +154,10 @@ create_character_intializer (gfc_expr *i if (len > end - start) { + gfc_warning_now ("Initialization string starting at %L was " + "truncated to fit the variable (%d/%d)", + &rvalue->where, len, end - start); len = end - start; - gfc_warning_now ("initialization string truncated to match variable " - "at %L", &rvalue->where); } if (rvalue->ts.type == BT_HOLLERITH)
:)
Subject: Bug 38404 Author: dfranke Date: Wed May 19 12:55:26 2010 New Revision: 159561 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159561 Log: gcc/fortran/: 2010-05-19 Daniel Franke <franke.daniel@gmail.com> PR fortran/38404 * primary.c (match_string_constant): Move start_locus just inside the string. * data.c (create_character_intializer): Clarified truncation warning. gcc/testsuite/: 2010-05-19 Daniel Franke <franke.daniel@gmail.com> PR fortran/38404 * gfortran.dg/data_char_1.f90: Updated warning message. * gfortran.dg/data_array_6.f: New. Added: trunk/gcc/testsuite/gfortran.dg/data_array_6.f Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/data.c trunk/gcc/fortran/primary.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/data_char_1.f90
Fixed in trunk. Closing. Thanks for the report!