diff mbox

[Fortran] PR64522 - reinstate truncation diagnostic

Message ID 20150108151049.GA28175@physik.fu-berlin.de
State New
Headers show

Commit Message

Tobias Burnus Jan. 8, 2015, 3:10 p.m. UTC
For fixed-form source code, it is not unusual that after the 72 columns,
comments are added - like sequence numbers with punch cards or later
code comments.

For free-form source code, that's very uncommon - especially as several
compilers do not honour the line limit of 132 characters (with default
settings).


Until and including GCC 4.4, gfortran was warning (unconditionally) when
free-form lines exceeded the line limit and got truncated. When some
additional diagnostic was introduced (PR39229, r151258, 2009-08-31), this
feature got lost. (Found by Andre - thanks!)

I think think it makes sense to have some diagnostic in this case. Either
by re-instating the warning or even by printing an error.

This patch does the latter by using the warning infrastructure.


For fixed-form source code, the result is as before:
* No warning by default
* -Wline-truncation (and -Wall) show a warning
* -Werror and -Werror=line-truncation turn it into an error

For free-form source code, the result was as above; it is now:
* By default, an error is printed ("[-Werror=line-truncation]")
* Using -Wall, -Wline-truncation, -Werror and -Werror=line-truncation
  also yield an error.
* -Wno-error=line-truncation and -Wno-error turn the error into a
  warning
* -Wno-line-truncation and -Wno-all silence the warning as well.

Build and regtested on x86-64-gnu-linux.
OK for the trunk? Or should only a warning be printed?

For GCC 4.8/4.9: Should we backport the patch (only printing the
warning, not the behaviour change)? Or given that the warning was
lost in 4.5, would it be sufficient to just modify the trunk?

Tobias
diff mbox

Patch

2015-01-08  Tobias Burnus  <burnus@net-b.de>

	PR fortran/64522
	* invoke.texi (Wline-truncation): Document new behaviour.
	* lang.opt (Wline-truncation): Add Init(-1).
	* options.c (gfc_post_options): If -Wline-truncation is unset,
	enable it for free-form source files; for the latter, also use
	-Werror=line-truncation, unless -Wno-error has been specified.

2015-01-08  Tobias Burnus  <burnus@net-b.de>

	PR fortran/64522
	* gfortran.dg/line_length_5.f90: Change dg-warning to dg-error
	and add dg-excess-errors.
	* gfortran.dg/line_length_6.f90: New.
	* gfortran.dg/line_length_7.f90: New.
	* gfortran.dg/line_length_8.f90: New.
	* gfortran.dg/line_length_9.f90: New.
	* gfortran.dg/line_length_10.f90: New.
	* gfortran.dg/line_length_11.f90: New.

diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 4cf36e8..39bc479 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -790,7 +790,9 @@  Warn when a character assignment will truncate the assigned string.
 @opindex @code{Wline-truncation}
 @cindex warnings, line truncation
 Warn when a source code line will be truncated.  This option is
-implied by @option{-Wall}.
+implied by @option{-Wall}.  For free-form source code, the default is
+@option{-Werror=line-truncation} such that truncations are reported as
+error.
 
 @item -Wconversion
 @opindex @code{Wconversion}
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index c4ebbe7..530ec97 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -250,7 +250,7 @@  Fortran Warning Var(warn_implicit_procedure)
 Warn about called procedures not explicitly declared
 
 Wline-truncation
-Fortran Warning Var(warn_line_truncation) LangEnabledBy(Fortran,Wall)
+Fortran Warning Var(warn_line_truncation) LangEnabledBy(Fortran,Wall) Init(-1)
 Warn about truncated source lines
 
 Wintrinsics-std
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index 24b13c1..70d4fa5 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -305,7 +305,20 @@  gfc_post_options (const char **pfilename)
 			   "in free form");
       else if (gfc_option.flag_d_lines == 1)
 	gfc_warning_now ("%<-fd-lines-as-code%> has no effect in free form");
+
+      if (warn_line_truncation == -1)
+	  warn_line_truncation = 1;
+
+      /* Enable -Werror=line-truncation when -Werror and -Wno-error have
+	 not been set.  */
+      if (warn_line_truncation && !global_options_set.x_warnings_are_errors
+	  && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
+	      DK_UNSPECIFIED))
+	diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
+					DK_ERROR, UNKNOWN_LOCATION);
     }
+  else if (warn_line_truncation == -1)
+    warn_line_truncation = 0;
 
   /* If -pedantic, warn about the use of GNU extensions.  */
   if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
diff --git a/gcc/testsuite/gfortran.dg/line_length_10.f90 b/gcc/testsuite/gfortran.dg/line_length_10.f90
new file mode 100644
index 0000000..390e9a1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/line_length_10.f90
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! { dg-options "-Wno-line-truncation" }
+!
+! By default, for free-form source code: Error out
+! But due to the explicit -Wno-line-truncation, compile w/o warning
+!
+      print *, 1                                                                                                                                          + 2
+      end
diff --git a/gcc/testsuite/gfortran.dg/line_length_11.f90 b/gcc/testsuite/gfortran.dg/line_length_11.f90
new file mode 100644
index 0000000..67f1e29
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/line_length_11.f90
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! { dg-options "-Wno-all" }
+!
+! By default, for free-form source code: Error out
+! But due to the explicit -Wno-all, compile w/o warning
+!
+      print *, 1                                                                                                                                          + 2
+      end
diff --git a/gcc/testsuite/gfortran.dg/line_length_4.f90 b/gcc/testsuite/gfortran.dg/line_length_4.f90
index 52bba1c..6e3c76e 100644
--- a/gcc/testsuite/gfortran.dg/line_length_4.f90
+++ b/gcc/testsuite/gfortran.dg/line_length_4.f90
@@ -15,4 +15,5 @@ 
      end do
    end subroutine foo
   end
-! { dg-warning "Line truncated" " " { target *-*-* } 8 }
+! { dg-error "Line truncated" " " { target *-*-* } 8 }
+! { dg-excess-errors "some warnings being treated as errors" }
diff --git a/gcc/testsuite/gfortran.dg/line_length_5.f90 b/gcc/testsuite/gfortran.dg/line_length_5.f90
index b9c2946..d7aca12 100644
--- a/gcc/testsuite/gfortran.dg/line_length_5.f90
+++ b/gcc/testsuite/gfortran.dg/line_length_5.f90
@@ -2,5 +2,6 @@ 
 ! { dg-options "-Wline-truncation" }
 print *, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
 end 
-! { dg-warning "Line truncated" " " { target *-*-* } 3 }
+! { dg-error "Line truncated" " " { target *-*-* } 3 }
 ! { dg-error "Unterminated character constant" " " { target *-*-* } 3 }
+! { dg-excess-errors "some warnings being treated as errors" }
diff --git a/gcc/testsuite/gfortran.dg/line_length_6.f90 b/gcc/testsuite/gfortran.dg/line_length_6.f90
new file mode 100644
index 0000000..92f3401
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/line_length_6.f90
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! { dg-options "" }
+!
+! By default, for free-form source code: Error out
+!
+      print *, 1                                                                                                                                          + 2 ! { dg-error "Line truncated at .1." }
+      end
+! { dg-excess-errors "some warnings being treated as errors" }
diff --git a/gcc/testsuite/gfortran.dg/line_length_7.f90 b/gcc/testsuite/gfortran.dg/line_length_7.f90
new file mode 100644
index 0000000..b4ebf49
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/line_length_7.f90
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! { dg-options "-Wno-error" }
+!
+! By default, for free-form source code: Error out
+! But due to -Wno-error, we only expect a warning
+!
+      print *, 1                                                                                                                                          + 2 ! { dg-warning "Line truncated at .1." }
+      end
diff --git a/gcc/testsuite/gfortran.dg/line_length_8.f90 b/gcc/testsuite/gfortran.dg/line_length_8.f90
new file mode 100644
index 0000000..3f0efaf
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/line_length_8.f90
@@ -0,0 +1,9 @@ 
+! { dg-do compile }
+! { dg-options "-Wline-truncation" }
+!
+! By default, for free-form source code: Error out
+! Even with -Wline-truncation, we still get an error
+!
+      print *, 1                                                                                                                                          + 2 ! { dg-error "Line truncated at .1." }
+      end
+! { dg-excess-errors "some warnings being treated as errors" }
diff --git a/gcc/testsuite/gfortran.dg/line_length_9.f90 b/gcc/testsuite/gfortran.dg/line_length_9.f90
new file mode 100644
index 0000000..f338972
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/line_length_9.f90
@@ -0,0 +1,9 @@ 
+! { dg-do compile }
+! { dg-options "-Wall" }
+!
+! By default, for free-form source code: Error out
+! Even with -Wall, we still get an error
+!
+      print *, 1                                                                                                                                          + 2 ! { dg-error "Line truncated at .1." }
+      end
+! { dg-excess-errors "some warnings being treated as errors" }