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]

semi-patch for pr 20845


Consider the following code.  Read the comment.
!
! { dg-do compile }
! PR 20845
!
! In ISO/IEC 1539-1:1997(E), 4th constraint in section 11.3:
!
!   If an object of a type for which component-initialization is specified
!   (R429) appears in the specification-part of a module and does not have
!   the ALLOCATABLE or POINTER attribute, the object shall have the SAVE
!   attribute.
!
module bad
   implicit none
   type default_initialization
      integer :: x = 42
   end type default_initialization
   type (default_initialization) t ! { dg-error "default initialization" }
end module bad

The last line needs a SAVE attribute.  I developed this patch:

Index: resolve.c
===================================================================
--- resolve.c	(revision 110319)
+++ resolve.c	(working copy)
@@ -4857,6 +4857,23 @@ resolve_symbol (gfc_symbol * sym)
 	  return;
 	}
 
+     /* 4th constraint in section 11.3:  "If an object of a type for which
+	component-initialization is specified (R429) appears in the
+	specification-part of a module and does not have the ALLOCATABLE
+	or POINTER attribute, the object shall have the SAVE attribute."  */
+
+      if (sym->ns->proc_name
+	  && sym->ns->proc_name->attr.flavor == FL_MODULE
+	  && sym->ts.type == BT_DERIVED && !(sym->value || flag)
+	  && !sym->ns->save_all && !sym->attr.save
+	  && !sym->attr.pointer && !sym->attr.allocatable)
+	{
+	  gfc_error("Object '%s' at %L must have the SAVE attribute %s",
+ 	 	     sym->name, &sym->declared_at,
+		     "for default initialization of a component");
+	  return;
+	}
+
       /* Assign default initializer.  */
       if (sym->ts.type == BT_DERIVED && !(sym->value || flag)
           && !sym->attr.pointer)


This appears to work with detecting the missing SAVE, but there are a
few test suite regressions.  First, my patch suggest that der_pointer_4.f90
is invalid code and I've verified this via Lahey's code checker.  The
regressions are derived_recursion.f90, host_used_types_1.f90,
used_dummy_types_1.f90, used_dummy_types_4.f90, used_types_1.f90, and
defined_types_2.f90.  I don't see why my patch is causing the regression,
so I'm hoping that someone (pault, tobi?) has some insight.





-- 
Steve


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