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] PR fortran/56520 -- Special case unary minus/plus


The attached patch special cases unary minus/plus when
gfotran tries to match a function keyword in a mangled
statement.  The testcase contains examples, but for
context consider 'c = exp(-a) )' where the final ')'
is erronous.  gfortran is trying to match a keyword
such as 'c = exp(x=-a)' so it expects the character
after the '(' to be in [a-z] or '_'.  Prior to this
patch, gfortran would do

% gfc -c sd.f90
sd.f90:8:13:

     c = exp(-a) )    ! dg-error { "Unclassifiable statement" }
             1
Error: Invalid character in name at (1)

with the patch gfortran will instead issue

% gfc -c sd.f90
sd.f90:8:4:

     c = exp(-a) )    ! dg-error { "Unclassifiable statement" }
    1
Error: Unclassifiable statement at (1)

It can be debated that the new error message isn't much better
than old.  I don't care to enter into such a debate, so will 
ignore comments complaining the new meesage isn't much of an
improvement over the old.

Regression tested on trunk.  Ok to commit?

2015-07-01  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/56520
	* match.c (gfc_match_name): Special case unary minus and plus.

2015-07-01  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/56520
	* gfortran.dg/pr56520.f90: New test.

-- 
Steve
Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c	(revision 224920)
+++ gcc/fortran/match.c	(working copy)
@@ -537,7 +537,10 @@ gfc_match_name (char *buffer)
   c = gfc_next_ascii_char ();
   if (!(ISALPHA (c) || (c == '_' && flag_allow_leading_underscore)))
     {
-      if (!gfc_error_flag_test () && c != '(')
+      /* Special cases for unary minus and plus, which allows for a sensible
+	 error message for code of the form 'c = exp(-a*b) )' where an
+	 extra ')' appears at the end of statement.  */
+      if (!gfc_error_flag_test () && c != '(' && c != '-' && c != '+')
 	gfc_error ("Invalid character in name at %C");
       gfc_current_locus = old_loc;
       return MATCH_NO;
Index: gcc/testsuite/gfortran.dg/pr56520.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr56520.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/pr56520.f90	(working copy)
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/56520
+!
+program misleading
+    implicit none
+    real a, c
+    a = 1.0
+    c = exp(+a) )    ! { dg-error "Unclassifiable statement" }
+    c = exp(-a) )    ! { dg-error "Unclassifiable statement" }
+    c = exp((a)) )   ! { dg-error "Unclassifiable statement" }
+    c = exp(a) )     ! { dg-error "Unclassifiable statement" }
+    c = exp(a)
+end program misleading

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