[patch, fortran] pr21061 - gfortran ignores -Werror

Bernhard Fischer rep.nop@aon.at
Thu Sep 14 12:59:00 GMT 2006


Hi,

:ADDPATCH fortran:

Attached is a revised and much simpler fix for PR fortran/21061 where
-Werror was ignored. The attached patch makes sure that we exit(1)
properly even for warnings.


It expects the improved error message that will be eventually
introduced to fix pr27698. It comes with two testcases, on for free- and
one for fixed format. The free format testcase trips one other bug that
is diagnostic related: fortran/trans-decl.c incorrectly uses
warning(0,...) instead of the gfc versions thereof ¹), but that is a
different issue.
Finally, i didn't see how to check for the proper return code (1 if
warnings/errors were seen and -Werror was given) in dg-do compile tests,
so the proper return value is not currently checked.

2006-09-14  Bernhard Fischer  <aldot@gcc.gnu.org>

	PR fortran/21061
	* error.c (gfc_warning): If warnings_are_errors then treat
	warnings as errors with respect to the exit code.
	(gfc_notify_std): Ditto.
	(gfc_warning_now): Ditto.


2006-09-14  Bernhard Fischer  <aldot@gcc.gnu.org>

	PR fortran/21061
	* gfortran.dg/warnings_are_errors.f: New test.
	* gfortran.dg/warnings_are_errors.f90: New test.


¹)
       function char_ (ch) ! { dg-warning "is obsolescent in fortran 95" }
       character(*) :: char_, ch
! warning(0,...):
       write (*,*) ch ! { dg-warning "Function does not return a value" }
       end function char_

thanks,
Bernhard

On Wed, Sep 13, 2006 at 02:04:19PM -0700, Steve Kargl wrote:
>On Wed, Jul 05, 2006 at 09:27:20PM +0200, Bernhard Fischer wrote:
>> 
>> Steve Kargl suggested a while ago that i'd resend the current
>> incarnation so he or somebody else could have a look.
>> 
>> Attached patch is against current trunk and emits the string 'error'
>> instead of 'warnings are treated as errors' once and then the usual
>> 'warning'/'error' string like the C frontend does.
>> 
>> thanks for suggestions WRT the string and the excess errors in the
>> testcases,
>> Bernhard
>> 
>
>I'll try to get a review of the patch out to you on Saturday.
>OTOH, if someone else has time to provide feedback, I'm sure
>Bernhard would not mind an earlier review.
-------------- next part --------------
Index: gcc-4.2/gcc/fortran/error.c
===================================================================
--- gcc-4.2/gcc/fortran/error.c	(revision 116887)
+++ gcc-4.2/gcc/fortran/error.c	(working copy)
@@ -475,7 +475,12 @@ gfc_warning (const char *nocmsgid, ...)
 
   va_start (argp, nocmsgid);
   if (buffer_flag == 0)
+  {
     warnings++;
+    if (warnings_are_errors)
+      errors++;
+  }
+
   error_print (_("Warning:"), _(nocmsgid), argp);
   va_end (argp);
 
@@ -518,14 +523,15 @@ gfc_notify_std (int std, const char *noc
 
   if (gfc_suppress_error)
     return warning ? SUCCESS : FAILURE;
-  
-  cur_error_buffer = warning ? &warning_buffer : &error_buffer;
+
+  cur_error_buffer = (warning && !warnings_are_errors)
+    ? &warning_buffer : &error_buffer;
   cur_error_buffer->flag = 1;
   cur_error_buffer->index = 0;
 
   if (buffer_flag == 0)
     {
-      if (warning)
+      if (warning && !warnings_are_errors)
 	warnings++;
       else
 	errors++;
@@ -538,7 +544,7 @@ gfc_notify_std (int std, const char *noc
   va_end (argp);
 
   error_char ('\0');
-  return warning ? SUCCESS : FAILURE;
+  return (warning && !warnings_are_errors) ? SUCCESS : FAILURE;
 }
 
 
@@ -556,6 +562,8 @@ gfc_warning_now (const char *nocmsgid, .
   i = buffer_flag;
   buffer_flag = 0;
   warnings++;
+  if (warnings_are_errors)
+    errors++;
 
   va_start (argp, nocmsgid);
   error_print (_("Warning:"), _(nocmsgid), argp);
Index: gcc-4.2/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f
===================================================================
--- gcc-4.2/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f	(revision 0)
+++ gcc-4.2/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f	(revision 0)
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-options "-std=f95 -Werror" }
+! PR fortran 21061
+! gfortran ignores -Werror
+! fixed-form tests
+       program warnings_are_errors_1
+       implicit none
+       integer(kind=1) :: i
+       real :: r1, r2(3)
+! gfc_warning_now:
+0      ! { dg-warning "Zero is not a valid statement label" }
+!
+34 5   i=0 
+! gfc_notify_std(GFC_STD_F95_DEL):
+       do r1 = 1.0, 2 ! { dg-error "Obsolete: REAL DO loop iterator" }
+         i = i+1
+       end do
+       call foo j bar
+       j = i-1 ! { dg-error "has no IMPLICIT type" }
+! gfc_warning:
+       r2(4) = 0 ! { dg-warning "is out of bounds" }
+       
+       goto 3 45
+       end
Index: gcc-4.2/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f90
===================================================================
--- gcc-4.2/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f90	(revision 0)
+++ gcc-4.2/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f90	(revision 0)
@@ -0,0 +1,55 @@
+! { dg-do compile }
+! { dg-options "-std=f95 -Werror" }
+! PR fortran 21061
+! gfortran ignores -Werror
+! free-form tests
+
+! gfc_notify_std:
+       function char_ (ch) ! { dg-warning "is obsolescent in fortran 95" }
+       character(*) :: char_, ch
+! warning(0,...):
+       write (*,*) ch ! { dg-warning "Function does not return a value" }
+       end function char_
+       implicit none
+
+TYPE :: seq_t
+ sequence
+ integer, dimension (:,:), pointer :: i_seq
+end type seq_t
+type (seq_t) :: my_seq
+
+type warn_t
+  integer i_warn
+! gfc_warning:
+end TYPE something_else ! { dg-error "label 'warn_t' for END TYPE statement" }
+end TYPE warn_t
+
+! gfc_error:
+real (kind=my_seq) :: r_seq1 ! { dg-error "has not been declared or is a variable, which does not reduce to a constant expr" }
+
+TYPE non_mod_type
+! gfc_error:
+ private ! { dg-error "must be inside a MODULE" }
+ integer :: i_non_mod
+end type non_mod_type
+
+! gfc_error:
+type (seq_t), dimension(0:my_seq), save :: r_seq2 ! { dg-error "must be of INTEGER type|must have constant shape" }
+       integer :: i
+4713  complex :: cplx
+!goto 4713 ! { no-error "not a valid branch target statement for the branch" }
+! gfc_warning:
+0815   goto 0815 ! { dg-error "causes an infinite loop" }
+
+0      ! { dg-error "Zero is not a valid statement label" }
+! gfc_warning_now:
+ 1 ! { dg-warning "Ignoring statement label in empty statement" }
+! gfc_error_now:
+34 5 ! { dg-error "Invalid character in name" }
+! gfc_error_now:
+34A5 ! { dg-error "Non-numeric character in statement label" }
+
+       call proc(j) ! { dg-error "has no IMPLICIT type" }
+       goto 3 45 ! { dg-error "Syntax error in GOTO statement" }
+       end
+


More information about the Fortran mailing list