diff mbox

[Fortran,F08] PR 60357: structure constructor with unspecified values for allocatable components

Message ID CAKwh3qjR4v8bYBNJqAJ56remHeAo4pYyf4YbaBuq7ZhiQaLuNQ@mail.gmail.com
State New
Headers show

Commit Message

Janus Weil Dec. 27, 2014, 5:35 p.m. UTC
Hi all,

here is a small patch for an F08 extension: Allocatable components
don't have to be specified in structure constructors any more.

Regtested on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus



2014-12-27  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/60357
    * array.c (check_constructor): Ignore empty expressions.
    * expr.c (check_alloc_comp_init): Check if constructor expression
    exists.
    * primary.c (build_actual_constructor): Warn for absent alloc-comp
    initializers in pre-2008 standards.

2014-12-27  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/60357
    * gfortran.dg/alloc_comp_constructor_7.f90: New.

Comments

Janus Weil Dec. 29, 2014, 10:51 a.m. UTC | #1
Hi Paul,

> It looks good to me. I wonder if the testcase should not changed to { dg-do
> run } and the allocatable component tested for not being allocated? You
> might also consider adding an allocatable array component too....
>
> OK for trunk modulo considerations above

those are good points you're making. I extended the test case
accordingly and committed the whole thing as r219098. Thanks for the
review!


> PS happy New Year!

Same to you and everyone else on this mailing list!

Cheers,
Janus



> On 27 December 2014 at 18:35, Janus Weil <janus@gcc.gnu.org> wrote:
>>
>> Hi all,
>>
>> here is a small patch for an F08 extension: Allocatable components
>> don't have to be specified in structure constructors any more.
>>
>> Regtested on x86_64-unknown-linux-gnu. Ok for trunk?
>>
>> Cheers,
>> Janus
>>
>>
>>
>> 2014-12-27  Janus Weil  <janus@gcc.gnu.org>
>>
>>     PR fortran/60357
>>     * array.c (check_constructor): Ignore empty expressions.
>>     * expr.c (check_alloc_comp_init): Check if constructor expression
>>     exists.
>>     * primary.c (build_actual_constructor): Warn for absent alloc-comp
>>     initializers in pre-2008 standards.
>>
>> 2014-12-27  Janus Weil  <janus@gcc.gnu.org>
>>
>>     PR fortran/60357
>>     * gfortran.dg/alloc_comp_constructor_7.f90: New.
>
>
>
>
> --
> The knack of flying is learning how to throw yourself at the ground and
> miss.
>        --Hitchhikers Guide to the Galaxy
diff mbox

Patch

Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(Revision 219082)
+++ gcc/fortran/array.c	(Arbeitskopie)
@@ -1309,6 +1309,9 @@  check_constructor (gfc_constructor_base ctor, bool
     {
       e = c->expr;
 
+      if (!e)
+	continue;
+
       if (e->expr_type != EXPR_ARRAY)
 	{
 	  if (!(*check_function)(e))
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(Revision 219082)
+++ gcc/fortran/expr.c	(Arbeitskopie)
@@ -2201,7 +2201,7 @@  check_alloc_comp_init (gfc_expr *e)
        ctor = gfc_constructor_first (e->value.constructor);
        comp; comp = comp->next, ctor = gfc_constructor_next (ctor))
     {
-      if (comp->attr.allocatable
+      if (comp->attr.allocatable && ctor->expr
           && ctor->expr->expr_type != EXPR_NULL)
         {
 	  gfc_error ("Invalid initialization expression for ALLOCATABLE "
Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(Revision 219082)
+++ gcc/fortran/primary.c	(Arbeitskopie)
@@ -2367,6 +2367,13 @@  build_actual_constructor (gfc_structure_ctor_compo
 		return false;
 	      value = gfc_copy_expr (comp->initializer);
 	    }
+	  else if (comp->attr.allocatable)
+	    {
+	      if (!gfc_notify_std (GFC_STD_F2008, "No initializer for "
+		  "allocatable component '%s' given in the structure "
+		  "constructor at %C", comp->name))
+		return false;
+	    }
 	  else if (!comp->attr.deferred_parameter)
 	    {
 	      gfc_error ("No initializer for component %qs given in the"