public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR38065 Fix checking of contained function
@ 2008-11-11 15:24 Tobias Burnus
  2008-11-12  4:31 ` Jerry DeLisle
  2008-11-12 15:27 ` Hans-Peter Nilsson
  0 siblings, 2 replies; 5+ messages in thread
From: Tobias Burnus @ 2008-11-11 15:24 UTC (permalink / raw)
  To: gcc-patches, 'fortran@gcc.gnu.org'

[-- Attachment #1: Type: text/plain, Size: 543 bytes --]

gfortran had two bugs:

a) A function, contained in a public module procedure, which returns a
private derived type, was rejected claiming that the function is public,
which is nonsense

b) A public module function, returning a private derived type was
rejected with -std=f2003, but they are only invalid in -std=f95.

The patch fixes both problems and should be save for the regression only
phase as it is simple and prints an error less often than before, which
makes it safe.

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

Tobias

[-- Attachment #2: privatetype.diff --]
[-- Type: text/plain, Size: 2582 bytes --]

2008-11-11  Tobias Burnus  <burnus@net-b.de>

	PR fortran/38065
	* resolve.c (resolve_fntype): Fix private derived type checking.

2008-11-11  Tobias Burnus  <burnus@net-b.de>

	PR fortran/38065
	* gfortran.dg/private_type_11.f90: New test.
	* gfortran.dg/private_type_12.f90: New test.

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 141763)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -10179,12 +10179,14 @@ resolve_fntype (gfc_namespace *ns)
     }
 
   if (sym->ts.type == BT_DERIVED && !sym->ts.derived->attr.use_assoc
+      && !sym->attr.contained
       && !gfc_check_access (sym->ts.derived->attr.access,
 			    sym->ts.derived->ns->default_access)
       && gfc_check_access (sym->attr.access, sym->ns->default_access))
     {
-      gfc_error ("PUBLIC function '%s' at %L cannot be of PRIVATE type '%s'",
-		 sym->name, &sym->declared_at, sym->ts.derived->name);
+      gfc_notify_std (GFC_STD_F2003, "Fortran 2003: PUBLIC function '%s' at "
+		      "%L of PRIVATE type '%s'", sym->name,
+		      &sym->declared_at, sym->ts.derived->name);
     }
 
     if (ns->entries)
Index: gcc/testsuite/gfortran.dg/private_type_11.f90
===================================================================
--- gcc/testsuite/gfortran.dg/private_type_11.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/private_type_11.f90	(Revision 0)
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+! PR fortran/38065
+!
+! Reported by Norman S. Clerman
+! and reduced by Joost VandeVondele
+!
+MODULE M1
+  IMPLICIT NONE
+  PRIVATE
+  TYPE T1
+   INTEGER :: I1
+  END TYPE T1
+  PUBLIC :: S1,F2
+CONTAINS
+  SUBROUTINE S1
+  CONTAINS
+   TYPE(T1) FUNCTION F1()
+   END FUNCTION F1
+  END SUBROUTINE S1
+  TYPE(T1) FUNCTION F2()
+  END FUNCTION F2
+END MODULE M1
Index: gcc/testsuite/gfortran.dg/private_type_12.f90
===================================================================
--- gcc/testsuite/gfortran.dg/private_type_12.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/private_type_12.f90	(Revision 0)
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+! PR fortran/38065
+!
+! Reported by Norman S. Clerman
+! and reduced by Joost VandeVondele
+!
+MODULE M1
+  IMPLICIT NONE
+  PRIVATE
+  TYPE T1
+   INTEGER :: I1
+  END TYPE T1
+  PUBLIC :: S1,F2
+CONTAINS
+  SUBROUTINE S1
+  CONTAINS
+   TYPE(T1) FUNCTION F1()
+   END FUNCTION F1
+  END SUBROUTINE S1
+  TYPE(T1) FUNCTION F2() ! { dg-error "Fortran 2003: PUBLIC variable 'f2'" }
+  END FUNCTION F2
+END MODULE M1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-12 18:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-11 15:24 [Patch, Fortran] PR38065 Fix checking of contained function Tobias Burnus
2008-11-12  4:31 ` Jerry DeLisle
2008-11-12 15:27 ` Hans-Peter Nilsson
2008-11-12 15:43   ` H.J. Lu
2008-11-12 19:03   ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).