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]

Re: [Patch, Fortran] F2008: Null pointer/non-allocated as absent dummy


Tobias Burnus wrote:
And yet another rather trivial F2008 change... (hours later) ... well, maybe it is not as trivial as I thought, but here it is.

The rules for absent actual arguments to optional dummies was changed from Fortran 2003 (12.4.1.6 Restrictions on dummy arguments not present) to Fortran 2008 (12.5.2.12 Argument presence and restrictions on arguments not present) by adding the following:

A dummy argument [...] is not present if the dummy argument [...]
does not have the ALLOCATABLE or POINTER attribute, and corresponds to an actual argument that
* has the ALLOCATABLE attribute and is not allocated, or
* has the POINTER attribute and is disassociated."


That mostly matches the current "present()" checks, except for descriptors (where the data element is NULL) and for directly passing EXPR_NULL. (At least I read it such that passing NULL() is allowed.) Thus, removing some checks - and changes for EXPR_NULL and assumed-shape arrays was all what was needed.

I also added a check that NULL() is not used for allocatable or non-optional dummies.

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

Yes.


I just don't really like the way

+      if (a->expr->expr_type == EXPR_NULL && !f->sym->attr.pointer
+	  && (f->sym->attr.allocatable || !f->sym->attr.optional
+	      || (gfc_option.allow_std & GFC_STD_F2008) == 0))
+	{
+	  if (where && (f->sym->attr.allocatable || !f->sym->attr.optional))
+	    gfc_error ("Unexpected NULL() intrinsic at %L to dummy '%s'",
+		       where, f->sym->name);
+	  else if (where)
+	    gfc_error ("Fortran 2008: Null pointer at %L to non-pointer "
+		       "dummy '%s'", where, f->sym->name);
+
+	  return 0;
+	}

is formulated; I'd probably do

if(where)
  {
     if(...)
     else
  }

instead of the if-elseif construct; and maybe the F2008 check first and the (ALLOCATABLE || !OPTIONAL) as else as this is a more complicated expression?

Just my personal taste, though.

Thanks for your patches,
Daniel

--
http://www.pro-vegan.info/
--
Done:  Arc-Bar-Cav-Ran-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri


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