This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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, Fortran] PR 44446 - Proc-pointer with PROTECTED


Hi all,

as Marco Restelli reported, the gfortran currently rejects a
procedure-pointer in the declaration part of a module if it has the
PROTECTED attribute. The protected <-> external/procedure check makes
sense, but not for procedure pointers.

As gfortran sets the EXTERNAL and PROCEDURE attribute for the PROCEDURE
statement and as one can write it as
  PROCEDURE(), PROTECTED :: foo
! which invalid by itself, but valid with the following line
  POINTER :: foo
the attribute check cannot be done in decl.c/symbol.c and thus I have
moved it to resolve.c.

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

Tobias


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

	PR fortran/44446
	* symbol.c (check_conflict): Move protected--external/procedure
	check ...
	* resolve.c (resolve_select_type): ... to the resolution stage.

Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c	(Revision 160375)
+++ gcc/fortran/symbol.c	(Arbeitskopie)
@@ -567,7 +567,6 @@ check_conflict (symbol_attribute *attr,
     }
 
   conf (is_protected, intrinsic)
-  conf (is_protected, external)
   conf (is_protected, in_common)
 
   conf (asynchronous, intrinsic)
@@ -587,7 +586,6 @@ check_conflict (symbol_attribute *attr,
   conf (procedure, dimension)
   conf (procedure, codimension)
   conf (procedure, intrinsic)
-  conf (procedure, is_protected)
   conf (procedure, target)
   conf (procedure, value)
   conf (procedure, volatile_)
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 160375)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -11311,6 +11313,19 @@ resolve_symbol (gfc_symbol *sym)
 	}
     }
 
+  if (sym->attr.is_protected && !sym->attr.proc_pointer
+      && (sym->attr.procedure || sym->attr.external))
+    {
+      if (sym->attr.external)
+	gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
+	           "at %L", &sym->declared_at);
+      else
+	gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
+	           "at %L", &sym->declared_at);
+
+      return;
+    }
+
   if (sym->attr.flavor == FL_DERIVED && resolve_fl_derived (sym) == FAILURE)
     return;
 
Index: gcc/testsuite/gfortran.dg/proc_ptr_27.f90
===================================================================
--- gcc/testsuite/gfortran.dg/proc_ptr_27.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/proc_ptr_27.f90	(Revision 0)
@@ -0,0 +1,20 @@
+! { dg-do compile }
+!
+! PR fortran/44446
+!
+! Contributed by Marco Restelli.
+!
+! Procedure pointer with PROTECTED was wrongly rejected.
+!
+module m
+ implicit none
+ abstract interface
+  pure function i_f(x) result(y)
+   real, intent(in) :: x
+   real :: y
+  end function i_f
+ end interface
+ procedure(i_f), pointer, protected :: p_f => null()
+end module m
+
+! { dg-final { cleanup-modules "m" } }

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