diff mbox series

[Committed] PR fortran/51991 -- Suppress a bogus SAVE error message

Message ID 20190621170223.GA54364@troutmask.apl.washington.edu
State New
Headers show
Series [Committed] PR fortran/51991 -- Suppress a bogus SAVE error message | expand

Commit Message

Steve Kargl June 21, 2019, 5:02 p.m. UTC
This PR was submitted on 2012-01-25.  It seems that I
posted a patch in comment #9 on 2012-01-25.  But the 
patch was never submitted to fortran@ and patches@.  The
patch is straight forward in that it suppresses a bogus
error message which then allows gfortran to issue a
more suitable error message.  It was past time to commit.

2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/51991
	* decl.c (gfc_match_save): If SAVE was not seen, return MATCH_NO
	instead issuing an error message and returning MATCH_ERROR.

2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/51991
	gfortran.dg/pr51991.f90
diff mbox series

Patch

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 272554)
+++ gcc/fortran/decl.c	(working copy)
@@ -9302,8 +9302,13 @@  gfc_match_save (void)
   return MATCH_YES;
 
 syntax:
-  gfc_error ("Syntax error in SAVE statement at %C");
-  return MATCH_ERROR;
+  if (gfc_current_ns->seen_save)
+    {
+      gfc_error ("Syntax error in SAVE statement at %C");
+      return MATCH_ERROR;
+    }
+  else
+      return MATCH_NO;
 }
 
 
Index: gcc/testsuite/gfortran.dg/pr51991.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr51991.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr51991.f90	(working copy)
@@ -0,0 +1,21 @@ 
+! { dg-do compile }
+! PR fortran/51991
+! Orginal code contributed by Sebastien Bardeau <bardeau at iram dot fr>
+module mymod
+  type :: mytyp
+    integer :: i
+  end type mytyp
+contains
+  subroutine mysub
+    implicit none
+    type(mytyp) :: a
+    integer :: i,j
+    i = a%i
+    !
+    ! Prior to patching gfortran, the following lined generated a syntax
+    ! error with the SAVE statement.  Now, gfortran generates an error
+    ! that indicates 'j' is not a component of 'mytyp'.
+    !
+    j = a%j    ! { dg-error "is not a member of the" }
+  end subroutine mysub
+end module mymod