This is the mail archive of the gcc-patches@gcc.gnu.org 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]

[patch, fortran] PR34536 - add default warning


Hi all.

As suggested by Tobias in PR34536, this patch gives a warning by default for 
invalid code as "2.0**-3*5". If -std=f*, an error is emitted instead.


:ADDPATCH fortran:

gcc/fortran:
2007-12-21  Daniel Franke  <franke.daniel@gmail.com>

	* matchexp.c (match_ext_mult_operand): Print warning for unary 
	operators following arithmetic ones by default.
	(match_ext_add_operand): Likewise.

gcc/testsuite:
2007-12-21  Daniel Franke  <franke.daniel@gmail.com>

	* gfortran.dg/integer_exponentiation_2.f90: Fixed testcase.
	* gfortran.dg/real_const_3.f90: Likewise.


Regression tested on i686-pc-linux-gnu, no errors. Ok for trunk?

Regards
	Daniel
Index: fortran/matchexp.c
===================================================================
--- fortran/matchexp.c	(revision 131109)
+++ fortran/matchexp.c	(working copy)
@@ -345,10 +345,15 @@ match_ext_mult_operand (gfc_expr **resul
   if (i == 0)
     return match_mult_operand (result);
 
-  if (gfc_notify_std (GFC_STD_GNU, "Extension: Unary operator following "
-		      "arithmetic operator (use parentheses) at %C")
-      == FAILURE)
-    return MATCH_ERROR;
+  if (gfc_notification_std (GFC_STD_GNU) == ERROR)
+    {
+      gfc_error ("Extension: Unary operator following "
+		 "arithmetic operator (use parentheses) at %C");
+      return MATCH_ERROR;
+    }
+  else
+    gfc_warning ("Extension: Unary operator following "
+		 "arithmetic operator (use parentheses) at %C");
 
   m = match_ext_mult_operand (&e);
   if (m != MATCH_YES)
@@ -449,10 +454,15 @@ match_ext_add_operand (gfc_expr **result
   if (i == 0)
     return match_add_operand (result);
 
-  if (gfc_notify_std (GFC_STD_GNU, "Extension: Unary operator following "
-		      "arithmetic operator (use parentheses) at %C")
-      == FAILURE)
-    return MATCH_ERROR;
+  if (gfc_notification_std (GFC_STD_GNU) == ERROR)
+    {
+      gfc_error ("Extension: Unary operator following "
+		 "arithmetic operator (use parentheses) at %C");
+      return MATCH_ERROR;
+    }
+  else
+    gfc_warning ("Extension: Unary operator following "
+		"arithmetic operator (use parentheses) at %C");
 
   m = match_ext_add_operand (&e);
   if (m != MATCH_YES)
Index: testsuite/gfortran.dg/integer_exponentiation_2.f90
===================================================================
--- testsuite/gfortran.dg/integer_exponentiation_2.f90	(revision 131109)
+++ testsuite/gfortran.dg/integer_exponentiation_2.f90	(working copy)
@@ -32,29 +32,29 @@ subroutine run_me(a, i, z)
   call check_equal_r (a**1.0, a)
   call check_equal_r (a**2.0, a*a)
   call check_equal_r (a**3.0, a*(a**2))
-  call check_equal_r (a**-1.0, 1/a)
-  call check_equal_r (a**-2.0, (1/a)*(1/a))
+  call check_equal_r (a**(-1.0), 1/a)
+  call check_equal_r (a**(-2.0), (1/a)*(1/a))
 
   call check_equal_r (a**0, 1.0)
   call check_equal_r (a**1, a)
   call check_equal_r (a**2, a*a)
   call check_equal_r (a**3, a*(a**2))
-  call check_equal_r (a**-1, 1/a)
-  call check_equal_r (a**-2, (1/a)*(1/a))
+  call check_equal_r (a**(-1), 1/a)
+  call check_equal_r (a**(-2), (1/a)*(1/a))
 
   call check_equal_r (a**0_8, 1.0)
   call check_equal_r (a**1_8, a)
   call check_equal_r (a**2_8, a*a)
   call check_equal_r (a**3_8, a*(a**2))
-  call check_equal_r (a**-1_8, 1/a)
-  call check_equal_r (a**-2_8, (1/a)*(1/a))
+  call check_equal_r (a**(-1_8), 1/a)
+  call check_equal_r (a**(-2_8), (1/a)*(1/a))
 
   call check_equal_c (z**0.0, (1.0,0.0))
   call check_equal_c (z**1.0, z)
   call check_equal_c (z**2.0, z*z)
   call check_equal_c (z**3.0, z*(z**2))
-  call check_equal_c (z**-1.0, 1/z)
-  call check_equal_c (z**-2.0, (1/z)*(1/z))
+  call check_equal_c (z**(-1.0), 1/z)
+  call check_equal_c (z**(-2.0), (1/z)*(1/z))
 
   call check_equal_c (z**(0.0,0.0), (1.0,0.0))
   call check_equal_c (z**(1.0,0.0), z)
@@ -67,15 +67,15 @@ subroutine run_me(a, i, z)
   call check_equal_c (z**1, z)
   call check_equal_c (z**2, z*z)
   call check_equal_c (z**3, z*(z**2))
-  call check_equal_c (z**-1, 1/z)
-  call check_equal_c (z**-2, (1/z)*(1/z))
+  call check_equal_c (z**(-1), 1/z)
+  call check_equal_c (z**(-2), (1/z)*(1/z))
 
   call check_equal_c (z**0_8, (1.0,0.0))
   call check_equal_c (z**1_8, z)
   call check_equal_c (z**2_8, z*z)
   call check_equal_c (z**3_8, z*(z**2))
-  call check_equal_c (z**-1_8, 1/z)
-  call check_equal_c (z**-2_8, (1/z)*(1/z))
+  call check_equal_c (z**(-1_8), 1/z)
+  call check_equal_c (z**(-2_8), (1/z)*(1/z))
 
 
 contains
@@ -110,44 +110,44 @@ subroutine foo(a)
   call gee_i(i**1_1)
   call gee_i(i**2_1)
   call gee_i(i**3_1)
-  call gee_i(i**-1_1)
-  call gee_i(i**-2_1)
-  call gee_i(i**-3_1)
+  call gee_i(i**(-1_1))
+  call gee_i(i**(-2_1))
+  call gee_i(i**(-3_1))
   call gee_i(i**huge(0_1))
-  call gee_i(i**-huge(0_1))
+  call gee_i(i**(-huge(0_1)))
   call gee_i(i**(-huge(0_1)-1_1))
 
   call gee_i(i**0_2)
   call gee_i(i**1_2)
   call gee_i(i**2_2)
   call gee_i(i**3_2)
-  call gee_i(i**-1_2)
-  call gee_i(i**-2_2)
-  call gee_i(i**-3_2)
+  call gee_i(i**(-1_2))
+  call gee_i(i**(-2_2))
+  call gee_i(i**(-3_2))
   call gee_i(i**huge(0_2))
-  call gee_i(i**-huge(0_2))
+  call gee_i(i**(-huge(0_2)))
   call gee_i(i**(-huge(0_2)-1_2))
 
   call gee_i(i**0_4)
   call gee_i(i**1_4)
   call gee_i(i**2_4)
   call gee_i(i**3_4)
-  call gee_i(i**-1_4)
-  call gee_i(i**-2_4)
-  call gee_i(i**-3_4)
+  call gee_i(i**(-1_4))
+  call gee_i(i**(-2_4))
+  call gee_i(i**(-3_4))
   call gee_i(i**huge(0_4))
-  call gee_i(i**-huge(0_4))
+  call gee_i(i**(-huge(0_4)))
   call gee_i(i**(-huge(0_4)-1_4))
 
   call gee_i(i**0_8)
   call gee_i(i**1_8)
   call gee_i(i**2_8)
   call gee_i(i**3_8)
-  call gee_i(i**-1_8)
-  call gee_i(i**-2_8)
-  call gee_i(i**-3_8)
+  call gee_i(i**(-1_8))
+  call gee_i(i**(-2_8))
+  call gee_i(i**(-3_8))
   call gee_i(i**huge(0_8))
-  call gee_i(i**-huge(0_8))
+  call gee_i(i**(-huge(0_8)))
   call gee_i(i**(-huge(0_8)-1_8))
 
   ! Real
@@ -155,44 +155,44 @@ subroutine foo(a)
   call gee_r(a**1_1)
   call gee_r(a**2_1)
   call gee_r(a**3_1)
-  call gee_r(a**-1_1)
-  call gee_r(a**-2_1)
-  call gee_r(a**-3_1)
+  call gee_r(a**(-1_1))
+  call gee_r(a**(-2_1))
+  call gee_r(a**(-3_1))
   call gee_r(a**huge(0_1))
-  call gee_r(a**-huge(0_1))
+  call gee_r(a**(-huge(0_1)))
   call gee_r(a**(-huge(0_1)-1_1))
 
   call gee_r(a**0_2)
   call gee_r(a**1_2)
   call gee_r(a**2_2)
   call gee_r(a**3_2)
-  call gee_r(a**-1_2)
-  call gee_r(a**-2_2)
-  call gee_r(a**-3_2)
+  call gee_r(a**(-1_2))
+  call gee_r(a**(-2_2))
+  call gee_r(a**(-3_2))
   call gee_r(a**huge(0_2))
-  call gee_r(a**-huge(0_2))
+  call gee_r(a**(-huge(0_2)))
   call gee_r(a**(-huge(0_2)-1_2))
 
   call gee_r(a**0_4)
   call gee_r(a**1_4)
   call gee_r(a**2_4)
   call gee_r(a**3_4)
-  call gee_r(a**-1_4)
-  call gee_r(a**-2_4)
-  call gee_r(a**-3_4)
+  call gee_r(a**(-1_4))
+  call gee_r(a**(-2_4))
+  call gee_r(a**(-3_4))
   call gee_r(a**huge(0_4))
-  call gee_r(a**-huge(0_4))
+  call gee_r(a**(-huge(0_4)))
   call gee_r(a**(-huge(0_4)-1_4))
 
   call gee_r(a**0_8)
   call gee_r(a**1_8)
   call gee_r(a**2_8)
   call gee_r(a**3_8)
-  call gee_r(a**-1_8)
-  call gee_r(a**-2_8)
-  call gee_r(a**-3_8)
+  call gee_r(a**(-1_8))
+  call gee_r(a**(-2_8))
+  call gee_r(a**(-3_8))
   call gee_r(a**huge(0_8))
-  call gee_r(a**-huge(0_8))
+  call gee_r(a**(-huge(0_8)))
   call gee_r(a**(-huge(0_8)-1_8))
 
   ! Complex
@@ -200,44 +200,44 @@ subroutine foo(a)
   call gee_z(z**1_1)
   call gee_z(z**2_1)
   call gee_z(z**3_1)
-  call gee_z(z**-1_1)
-  call gee_z(z**-2_1)
-  call gee_z(z**-3_1)
+  call gee_z(z**(-1_1))
+  call gee_z(z**(-2_1))
+  call gee_z(z**(-3_1))
   call gee_z(z**huge(0_1))
-  call gee_z(z**-huge(0_1))
+  call gee_z(z**(-huge(0_1)))
   call gee_z(z**(-huge(0_1)-1_1))
 
   call gee_z(z**0_2)
   call gee_z(z**1_2)
   call gee_z(z**2_2)
   call gee_z(z**3_2)
-  call gee_z(z**-1_2)
-  call gee_z(z**-2_2)
-  call gee_z(z**-3_2)
+  call gee_z(z**(-1_2))
+  call gee_z(z**(-2_2))
+  call gee_z(z**(-3_2))
   call gee_z(z**huge(0_2))
-  call gee_z(z**-huge(0_2))
+  call gee_z(z**(-huge(0_2)))
   call gee_z(z**(-huge(0_2)-1_2))
 
   call gee_z(z**0_4)
   call gee_z(z**1_4)
   call gee_z(z**2_4)
   call gee_z(z**3_4)
-  call gee_z(z**-1_4)
-  call gee_z(z**-2_4)
-  call gee_z(z**-3_4)
+  call gee_z(z**(-1_4))
+  call gee_z(z**(-2_4))
+  call gee_z(z**(-3_4))
   call gee_z(z**huge(0_4))
-  call gee_z(z**-huge(0_4))
+  call gee_z(z**(-huge(0_4)))
   call gee_z(z**(-huge(0_4)-1_4))
 
   call gee_z(z**0_8)
   call gee_z(z**1_8)
   call gee_z(z**2_8)
   call gee_z(z**3_8)
-  call gee_z(z**-1_8)
-  call gee_z(z**-2_8)
-  call gee_z(z**-3_8)
+  call gee_z(z**(-1_8))
+  call gee_z(z**(-2_8))
+  call gee_z(z**(-3_8))
   call gee_z(z**huge(0_8))
-  call gee_z(z**-huge(0_8))
+  call gee_z(z**(-huge(0_8)))
   call gee_z(z**(-huge(0_8)-1_8))
 end subroutine foo
 
Index: testsuite/gfortran.dg/real_const_3.f90
===================================================================
--- testsuite/gfortran.dg/real_const_3.f90	(revision 131109)
+++ testsuite/gfortran.dg/real_const_3.f90	(working copy)
@@ -28,7 +28,7 @@ program main
   write(str,*) 0.0/0.0
   if (trim(adjustl(str)) .ne. 'NaN') call abort
 
-  write(str,*) 1.0/-0.
+  write(str,*) 1.0/(-0.)
   if (trim(adjustl(str)) .ne. '-Infinity') call abort
 
   write(str,*) -2.0/0.

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