This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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] PR33106 - F95 reject public entries to private derived types


:ADDPATCH fortran:

For details, see PR and links therein. The following is invalid Fortran
95, but valid Fortran 2003; gfortran was accepting it with -std=f95:

module m
  implicit none
  type, private :: hidden_type
    character(6) :: code
  end type
  type(hidden_type), public, parameter :: code_green = hidden_type('green')
  type(hidden_type), public, parameter :: code_yellow = hidden_type('yellow')
  type(hidden_type), public, parameter :: code_red = hidden_type('red')
end module m


Build and regression tested on x86_64-unknown-linux-gnu with no new
failures.

Ok for the trunk?

Tobias
2007-09-12  Tobias Burnus  <burnus@net-b.de>

	PR fortran/33106
	* resolve.c (resolve_symbol): Reject public variable of
	private derived-types for Fortran 95.

2007-09-12  Tobias Burnus  <burnus@net-b.de>

	PR fortran/33106
	* gfortran.dg/private_type_9.f90: New.

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 128444)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -7579,6 +7584,22 @@ resolve_symbol (gfc_symbol *sym)
       return;
     }
 
+  /* Unless the derived-type declaration is use associated, Fortran 95
+     does not allow public entries of private derived types.
+     See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
+     161 in 95-006r3.  */
+  if (sym->ts.type == BT_DERIVED
+      && gfc_check_access (sym->attr.access, sym->ns->default_access)
+      && !gfc_check_access (sym->ts.derived->attr.access,
+			    sym->ts.derived->ns->default_access)
+      && !sym->ts.derived->attr.use_assoc
+      && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: PUBLIC %s '%s' at %L "
+		         "of PRIVATE derived type '%s'",
+			 (sym->attr.flavor == FL_PARAMETER) ? "parameter"
+			 : "variable", sym->name, &sym->declared_at,
+			 sym->ts.derived->name) == FAILURE)
+    return;
+
   /* An assumed-size array with INTENT(OUT) shall not be of a type for which
      default initialization is defined (5.1.2.4.4).  */
   if (sym->ts.type == BT_DERIVED
Index: gcc/testsuite/gfortran.dg/private_type_9.f90
===================================================================
--- gcc/testsuite/gfortran.dg/private_type_9.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/private_type_9.f90	(Revision 0)
@@ -0,0 +1,41 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+!
+! PR fortran/33106
+!
+module m1
+  implicit none
+  type, private :: t
+    integer :: i
+  end type t
+  type(t), public :: one ! { dg-error "PRIVATE derived type" }
+  type(t), public, parameter :: two = t(2) ! { dg-error "PRIVATE derived type" }
+end module m1
+
+module m2
+  implicit none
+  private
+  type t
+    integer :: i
+  end type t
+  type(t), public :: one ! { dg-error "PRIVATE derived type" }
+  type(t), public, parameter :: two = t(2) ! { dg-error "PRIVATE derived type" }
+end module m2
+
+module m3
+  implicit none
+  type t
+    integer :: i
+  end type t
+end module m3
+
+module m4
+  use m3!, only: t
+  implicit none
+  private 
+  private :: t
+  type(t), public :: one
+  type(t), public, parameter :: two = t(2)
+end module m4
+
+end

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