This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fortran, Patch, Diagnostics] PR fortran/39171: Change misleading warning about negative CHARACTER length


for a CHARACTER variable with negative length like

CHARACTER(len=-5) :: abc

gfortran did so far produce the warning "has zero length" which is obviously wrong (the length is changed to zero, as required by the standard).

This patch changes the message to be correct and enables this warning only with -Wsurprising.

Regression testing at the moment on GNU/Linux-x86-32, ok for trunk if no failures?


Done:  Arc-Bar-Cav-Ran-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri
2010-02-09  Daniel Kraft  <>

	PR fortran/39171
	* resolve.c (resolve_charlen): Change warning about negative CHARACTER
	length to be correct and issue only with -Wsurprising.
	* invoke.texi (Wsurprising): Mention this new warning that is
	turned on by -Wsurprising.

2010-02-09  Daniel Kraft  <>

	PR fortran/39171
	* gfortran.dg/char_length_2.f90: Change warning expectations accordingly
	and pass -Wsurprising as necessary.
Index: gcc/fortran/invoke.texi
--- gcc/fortran/invoke.texi	(revision 156447)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -792,6 +792,9 @@ A TRANSFER specifies a source that is sh
 The type of a function result is declared more than once with the same type.  If
 @option{-pedantic} or standard-conforming mode is enabled, this is an error.
+A @code{CHARACTER} variable is declared with negative length.
 @end itemize
 @item -Wtabs
Index: gcc/fortran/resolve.c
--- gcc/fortran/resolve.c	(revision 156447)
+++ gcc/fortran/resolve.c	(working copy)
@@ -8559,8 +8559,10 @@ resolve_charlen (gfc_charlen *cl)
      value, the length of character entities declared is zero."  */
   if (cl->length && !gfc_extract_int (cl->length, &i) && i < 0)
-      gfc_warning_now ("CHARACTER variable has zero length at %L",
-		       &cl->length->where);
+      if (gfc_option.warn_surprising)
+	gfc_warning_now ("CHARACTER variable at %L has negative length %d,"
+			 " the length has been set to zero",
+			 &cl->length->where, i);
       gfc_replace_expr (cl->length, gfc_int_expr (0));
Index: gcc/testsuite/gfortran.dg/char_length_2.f90
--- gcc/testsuite/gfortran.dg/char_length_2.f90	(revision 156447)
+++ gcc/testsuite/gfortran.dg/char_length_2.f90	(working copy)
@@ -1,13 +1,14 @@
 ! { dg-do link }
+! { dg-options "-Wsurprising" }
 ! Tests the fix for PR 31250
 ! CHARACTER lengths weren't reduced early enough for all checks of
 ! them to be meaningful.  Furthermore negative string lengths weren't
 ! dealt with correctly.
 CHARACTER(len=0) :: c1   ! This is OK.
-CHARACTER(len=-1) :: c2  ! { dg-warning "CHARACTER variable has zero length" }
+CHARACTER(len=-1) :: c2  ! { dg-warning "has negative length" }
-CHARACTER(len=I) :: c3   ! { dg-warning "CHARACTER variable has zero length" }
-CHARACTER(len=min(I,500)) :: c4  ! { dg-warning "CHARACTER variable has zero length" }
+CHARACTER(len=I) :: c3   ! { dg-warning "has negative length" }
+CHARACTER(len=min(I,500)) :: c4  ! { dg-warning "has negative length" }
 CHARACTER(len=max(I,500)) :: d1  ! no warning
 CHARACTER(len=5) :: d2   ! no warning

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]