This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH(es)] PR fortran/77391 -- RFC vote on which you prefer
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: Mikael Morin <morin-mikael at orange dot fr>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 26 Aug 2016 17:06:05 -0700
- Subject: Re: [PATCH(es)] PR fortran/77391 -- RFC vote on which you prefer
- Authentication-results: sourceware.org; auth=none
- References: <20160826182755.GA63696@troutmask.apl.washington.edu> <c402a0eb-9c23-9d87-5cfd-1b8c01a79fd7@orange.fr>
- Reply-to: kargl at uw dot edu
On Fri, Aug 26, 2016 at 10:28:25PM +0200, Mikael Morin wrote:
> Hello,
>
> Le 26/08/2016 à 20:27, Steve Kargl a écrit :
> > Here are two possible patches for PR fortran/77391. The first
> > patch treats the invalid code as a GNU Fortran extension as
> > gfortran current accepts the invalid code. The second patch
> > enforces the standard. As I think gfortran should encourage
> > standard conformance, I am inclined to commit the second patch.
> > I will however commit the most popular of the two patches tomorrow.
> > Voting starts now and will remain open for 24 hours (give or take
> > a few hours depend on when I awaken).
> >
>
> I don't think it's sufficient to check current_attr because of this case:
>
> character(:) :: a
> pointer :: a
> end
>
> The statement should be accepted, and the check be postponed at a time
> after the symbol has been initialised, at resolution time for example.
>
So, I've come up the following. We now need to debate whether
Dominiq's observations mean that C402 does not apply to named
constant.
2016-08-26 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/77391
* resolve.c (deferred_requirements): New function to check F2008:C402.
(resolve_fl_variable,resolve_fl_parameter): Use it.
2016-08-26 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/77391
* gfortran.dg/pr77391.f90: New test.
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 239762)
+++ gcc/fortran/resolve.c (working copy)
@@ -11402,6 +11402,27 @@ resolve_fl_variable_derived (gfc_symbol
}
+/* F2008, C402 (R401): A colon shall not be used as a type-param-value
+ except in the declaration of an entity or component that has the POINTER
+ or ALLOCATABLE attribute. */
+
+static bool
+deferred_requirements (gfc_symbol *sym)
+{
+ if (sym->ts.deferred
+ && !(sym->attr.pointer
+ || sym->attr.allocatable
+ || sym->attr.omp_udr_artificial_var))
+ {
+ gfc_error ("Entity %qs at %L has a deferred type parameter and "
+ "requires either the POINTER or ALLOCATABLE attribute",
+ sym->name, &sym->declared_at);
+ return false;
+ }
+ return true;
+}
+
+
/* Resolve symbols with flavor variable. */
static bool
@@ -11441,17 +11462,8 @@ resolve_fl_variable (gfc_symbol *sym, in
}
/* Constraints on deferred type parameter. */
- if (sym->ts.deferred
- && !(sym->attr.pointer
- || sym->attr.allocatable
- || sym->attr.omp_udr_artificial_var))
- {
- gfc_error ("Entity %qs at %L has a deferred type parameter and "
- "requires either the pointer or allocatable attribute",
- sym->name, &sym->declared_at);
- specification_expr = saved_specification_expr;
- return false;
- }
+ if (!deferred_requirements (sym))
+ return false;
if (sym->ts.type == BT_CHARACTER)
{
@@ -13570,6 +13582,10 @@ resolve_fl_parameter (gfc_symbol *sym)
return false;
}
+ /* Constraints on deferred type parameter. */
+ if (!deferred_requirements (sym))
+ return false;
+
/* Make sure a parameter that has been implicitly typed still
matches the implicit type, since PARAMETER statements can precede
IMPLICIT statements. */
Index: gcc/testsuite/gfortran.dg/pr77391.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr77391.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77391.f90 (working copy)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+program picky
+character(len=:), parameter :: a="whoops" ! { dg-error "POINTER or ALLOCATABLE" }
+character(len=:) :: b="whoops" ! { dg-error "POINTER or ALLOCATABLE" }
+character(len=:) :: good
+pointer good
+end program picky
--
Steve