Patchwork [Fortran] F2008 allow END besides END SUBROUTINE/FUNCTION in contained procedures

login
register
mail settings
Submitter Tobias Burnus
Date June 25, 2010, 6:20 p.m.
Message ID <4C24F35A.4010606@net-b.de>
Download mbox | patch
Permalink /patch/56941/
State New
Headers show

Comments

Tobias Burnus - June 25, 2010, 6:20 p.m.
Another trivial F2008 change. The following Fortran 2003 constraint has
been removed:

C1243 (R1230) FUNCTION shall appear in the end-function-stmt of an
internal or module function.

(By the way, the "Introduction" of the F2008 standard lists the most
important changes - such as this one.)

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
Jerry DeLisle - June 25, 2010, 6:46 p.m.
On 06/25/2010 11:20 AM, Tobias Burnus wrote:
> Another trivial F2008 change. The following Fortran 2003 constraint has
> been removed:
>
> C1243 (R1230) FUNCTION shall appear in the end-function-stmt of an
> internal or module function.
>
> (By the way, the "Introduction" of the F2008 standard lists the most
> important changes - such as this one.)
>
> Build and regtested on x86-64-linux.
> OK for the trunk?
>
> Tobias

This is OK.

Jerry

Patch

2010-06-25  Tobias Burnus  <burnus@net-b.de>

	* decl.c (gfc_match_entry): Allow END besides
	END SUBROUTINE/END FUNCTION for contained procedures.

2010-06-25  Tobias Burnus  <burnus@net-b.de>

	* gfortran.dg/end_subroutine_1.f90: New.
	* gfortran.dg/end_subroutine_2.f90: New.
	* gfortran.dg/interface_proc_end.f90: Update.

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(Revision 161388)
+++ gcc/fortran/decl.c	(Arbeitskopie)
@@ -5642,7 +5646,14 @@  gfc_match_end (gfc_statement *st)
 
   if (gfc_match_eos () == MATCH_YES)
     {
-      if (!eos_ok)
+      if (!eos_ok && (*st == ST_END_SUBROUTINE || *st == ST_END_FUNCTION))
+	{
+	  if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: END statement "
+			      "instead of %s statement at %L",
+			      gfc_ascii_statement (*st), &old_loc) == FAILURE)
+	    goto cleanup;
+	}
+      else if (!eos_ok)
 	{
 	  /* We would have required END [something].  */
 	  gfc_error ("%s statement expected at %L",
Index: gcc/testsuite/gfortran.dg/end_subroutine_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/end_subroutine_1.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/end_subroutine_1.f90	(Revision 0)
@@ -0,0 +1,16 @@ 
+! { dg-do compile }
+! { dg-options "-std=f2008" }
+!
+interface
+  subroutine foo()
+  end 
+  integer function bar()
+  end 
+end interface
+contains
+  subroutine test()
+  end
+  integer function f()
+    f = 42
+  end
+end
Index: gcc/testsuite/gfortran.dg/end_subroutine_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/end_subroutine_2.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/end_subroutine_2.f90	(Revision 0)
@@ -0,0 +1,24 @@ 
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+!
+program main
+interface
+  subroutine foo()
+  end 
+  integer function bar()
+  end 
+end interface
+contains
+  subroutine test()
+  end ! { dg-error "Fortran 2008: END statement instead of END SUBROUTINE" }
+  end subroutine  ! To silence successive errors
+end program
+
+subroutine test2()
+contains
+  integer function f()
+    f = 42
+  end ! { dg-error "Fortran 2008: END statement instead of END FUNCTION" }
+  end function  ! To silence successive errors
+end subroutine test2
+
Index: gcc/testsuite/gfortran.dg/interface_proc_end.f90
===================================================================
--- gcc/testsuite/gfortran.dg/interface_proc_end.f90	(Revision 161388)
+++ gcc/testsuite/gfortran.dg/interface_proc_end.f90	(Arbeitskopie)
@@ -14,6 +14,5 @@ 
             REAL  ::  TLS1,TLS2
             END ! OK
       END INTERFACE
-      end ! { dg-error "END SUBROUTINE statement" }
-      end module ! { dg-error "END SUBROUTINE statement" }
-! { dg-error "Unexpected end of file" "" { target "*-*-*" } 0 }
+      end subroutine
+      end module