This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] Reject duplicated PURE/ELEMENTAL/RECURSIVE
- 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: Wed, 12 Sep 2007 23:19:04 +0200
- Subject: [Patch, Fortran] Reject duplicated PURE/ELEMENTAL/RECURSIVE
:ADDPATCH fortran:
R1227 prefix is prefix-spec [ prefix-spec ] ...
R1228 prefix-spec is declaration-type-spec
or RECURSIVE
or PURE
or ELEMENTAL
C1240 (R1227) A prefix shall contain at most one of each prefix-spec.
Build and regression tested on x86_64-unknown-linux-gnu.
Ok for the trunk?
Tobias
2007-09-12 Tobias Burnus <burnus@net-b.de>
* symbol.c (gfc_add_elemental,gfc_add_pure,gfc_add_recursive):
Reject allow prefixes only to be specified once.
2007-09-12 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/recursive_check_3.f90: New.
Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c (revision 128444)
+++ gcc/fortran/symbol.c (working copy)
@@ -1143,6 +1144,12 @@ gfc_add_elemental (symbol_attribute *att
if (check_used (attr, NULL, where))
return FAILURE;
+ if (attr->elemental)
+ {
+ duplicate_attr ("ELEMENTAL", where);
+ return FAILURE;
+ }
+
attr->elemental = 1;
return check_conflict (attr, NULL, where);
}
@@ -1155,6 +1162,12 @@ gfc_add_pure (symbol_attribute *attr, lo
if (check_used (attr, NULL, where))
return FAILURE;
+ if (attr->pure)
+ {
+ duplicate_attr ("PURE", where);
+ return FAILURE;
+ }
+
attr->pure = 1;
return check_conflict (attr, NULL, where);
}
@@ -1167,6 +1180,12 @@ gfc_add_recursive (symbol_attribute *att
if (check_used (attr, NULL, where))
return FAILURE;
+ if (attr->recursive)
+ {
+ duplicate_attr ("RECURSIVE", where);
+ return FAILURE;
+ }
+
attr->recursive = 1;
return check_conflict (attr, NULL, where);
}
Index: gcc/testsuite/gfortran.dg/recursive_check_3.f90
===================================================================
--- gcc/testsuite/gfortran.dg/recursive_check_3.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/recursive_check_3.f90 (revision 0)
@@ -0,0 +1,22 @@
+! { dg-do compile }
+!
+module m1
+contains
+pure pure subroutine a1(b) ! { dg-error "Duplicate PURE attribute specified" }
+ real, intent(in) :: b ! { dg-error "Unexpected data declaration statement" }
+end subroutine a1 ! { dg-error "Expecting END MODULE" }
+end module m1 ! { dg-warning "CONTAINS statement without FUNCTION" }
+
+module m2
+contains
+elemental elemental subroutine a2(b) ! { dg-error "Duplicate ELEMENTAL attribute" }
+ real, intent(in) :: b ! { dg-error "Unexpected data declaration statement" }
+end subroutine a2 ! { dg-error "Expecting END MODULE" }
+end module m2 ! { dg-warning "CONTAINS statement without FUNCTION" }
+
+module m3
+contains
+recursive recursive subroutine a3(b) ! { dg-error "Duplicate RECURSIVE attribute" }
+ real, intent(in) :: b ! { dg-error "Unexpected data declaration statement" }
+end subroutine a3 ! { dg-error "Expecting END MODULE" }
+end module m3 ! { dg-warning "CONTAINS statement without FUNCTION" }