This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Fortran, patch] Give an error for empty CONTAINS statemens for F95/F2003 (PR29806)
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 13 Nov 2006 19:53:41 +0100
- Subject: [Fortran, patch] Give an error for empty CONTAINS statemens for F95/F2003 (PR29806)
:ADDPATCH fortran:
The Fortran 95 and 2003 standard prohibit to use CONTAINS without an
internal-subprogram or module-subprogram.
(See R1101, R210 and R1107 in the Fortran 2003 standard.)
All compilers I tested reject this.
As Erik pointed out, Fortran 2008 lifts this restriction (at least it is
lifted in 06-007r1.pdf); thus I didn't use gfc_error but allowed it in
STD_GNU.
I needed to change derived_function_interface_1.f90 as with -pedantic a
warning is given.
I did only add a check for the error, I didn't add a check whether no
error is given without -std=f95.
(This is implicitly tested by derived_function_interface_1.f90, which
only gives a warning.)
Build and regression-tested on x86_64-unknown-linux-gnu.
Tobias
fortran/
2006-11-13 Tobias Burnus <burnus@net-b.de>
* parse.c (parse_contained): Check for empty contains statement.
testsuite/
2006-11-13 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/contains.f90: Added.
Index: gcc/fortran/parse.c
===================================================================
*** gcc/fortran/parse.c (Revision 118763)
--- gcc/fortran/parse.c (Arbeitskopie)
*************** parse_contained (int module)
*** 2757,2762 ****
--- 2770,2776 ----
gfc_statement st;
gfc_symbol *sym;
gfc_entry_list *el;
+ int contains_statements = 0;
push_state (&s1, COMP_CONTAINS, NULL);
parent_ns = gfc_current_ns;
*************** parse_contained (int module)
*** 2777,2782 ****
--- 2791,2797 ----
case ST_FUNCTION:
case ST_SUBROUTINE:
+ contains_statements = 1;
accept_statement (st);
push_state (&s2,
*************** parse_contained (int module)
*** 2860,2865 ****
--- 2875,2885 ----
gfc_free_namespace (ns);
pop_state ();
+ if (!contains_statements)
+ /* This is valid in Fortran 2008 */
+ gfc_notify_std (GFC_STD_GNU, "Extension: "
+ "CONTAINS statement without FUNCTION "
+ "or SUBROUTINE statement at %C.");
}
Index: gcc/testsuite/gfortran.dg/derived_function_interface_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/derived_function_interface_1.f90 (Revision 118763)
--- gcc/testsuite/gfortran.dg/derived_function_interface_1.f90 (Arbeitskopie)
*************** contains
*** 37,40 ****
type(foo) function fun() ! { dg-error "already has an explicit interface" }
end function fun ! { dg-error "Expecting END PROGRAM" }
! end
--- 37,40 ----
type(foo) function fun() ! { dg-error "already has an explicit interface" }
end function fun ! { dg-error "Expecting END PROGRAM" }
! end ! { dg-warning "CONTAINS statement without FUNCTION or SUBROUTINE statement" }
--- /dev/null 2006-10-21 23:34:46.000000000 +0200
+++ gcc/testsuite/gfortran.dg/contains.f90 2006-11-13 19:40:14.000000000 +0100
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+! Check whether empty contains are allowd
+! PR fortran/29806
+module x
+ contains
+end module x ! { dg-error "CONTAINS statement without FUNCTION or SUBROUTINE statement" }
+
+program y
+ contains
+end program y ! { dg-error "CONTAINS statement without FUNCTION or SUBROUTINE statement" }