diff mbox

[Fortran] PR64943 Fix I/O diagnostic for structure constructors

Message ID 54D3DAD4.9020503@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Feb. 5, 2015, 9:04 p.m. UTC
A rather simple patch.

Build and reg-tested on x86-64-gnu-linux.
OK for the trunk?

Tobias

Comments

Paul Richard Thomas Feb. 5, 2015, 9:18 p.m. UTC | #1
Dear Tobias,

That is OK for trunk.

Thanks for the patch.

Paul

On 5 February 2015 at 22:04, Tobias Burnus <burnus@net-b.de> wrote:
> A rather simple patch.
>
> Build and reg-tested on x86-64-gnu-linux.
> OK for the trunk?
>
> Tobias
diff mbox

Patch

2015-02-05  Tobias Burnus  <burnus@net-b.de>

	PR fortran/64943
	* resolve.c (resolve_transfer): Also check structure
	constructors.

2015-02-05  Tobias Burnus  <burnus@net-b.de>

	PR fortran/64943
	* gfortran.dg/structure_constructor_12.f90: New.

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 3b0c12a..0b188da 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -8364,7 +8364,8 @@  resolve_transfer (gfc_code *code)
     }
 
   if (exp == NULL || (exp->expr_type != EXPR_VARIABLE
-		      && exp->expr_type != EXPR_FUNCTION))
+		      && exp->expr_type != EXPR_FUNCTION
+		      && exp->expr_type != EXPR_STRUCTURE))
     return;
 
   /* If we are reading, the variable will be changed.  Note that
@@ -8375,8 +8376,7 @@  resolve_transfer (gfc_code *code)
 				    _("item in READ")))
     return;
 
-  sym = exp->symtree->n.sym;
-  ts = &sym->ts;
+  ts = exp->expr_type == EXPR_STRUCTURE ? &exp->ts : &exp->symtree->n.sym->ts;
 
   /* Go to actual component transferred.  */
   for (ref = exp->ref; ref; ref = ref->next)
@@ -8436,6 +8436,11 @@  resolve_transfer (gfc_code *code)
 	  return;
 	}
     }
+   
+  if (exp->expr_type == EXPR_STRUCTURE)
+    return;
+
+  sym = exp->symtree->n.sym;
 
   if (sym->as != NULL && sym->as->type == AS_ASSUMED_SIZE && exp->ref
       && exp->ref->type == REF_ARRAY && exp->ref->u.ar.type == AR_FULL)
diff --git a/gcc/testsuite/gfortran.dg/structure_constructor_12.f90 b/gcc/testsuite/gfortran.dg/structure_constructor_12.f90
new file mode 100644
index 0000000..aa7e91d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/structure_constructor_12.f90
@@ -0,0 +1,15 @@ 
+! { dg-do compile }
+!
+! PR fortran/64943
+!
+! Contributed Dominique d'Humieres
+!
+  type :: Test
+    integer :: i
+  end type
+
+  type :: TestReference
+     class(Test), allocatable :: test(:)
+  end type
+print *, TestReference([Test(99), Test(199)]) ! { dg-error "Data transfer element at .1. cannot have ALLOCATABLE components unless it is processed by a defined input/output procedure" }
+end