PR 83975 Associate target with non-constant character length

Message ID 1517475920-28814-1-git-send-email-blomqvist.janne@gmail.com
State New
Headers show
Series
  • PR 83975 Associate target with non-constant character length
Related show

Commit Message

Janne Blomqvist Feb. 1, 2018, 9:05 a.m.
When associating a variable of type character, if the length of the
target isn't known at compile time, generate an error. See PR 83344
for more details.

Regtested on x86_64-pc-linux-gnu, Ok for trunk?

gcc/fortran/ChangeLog:

2018-02-01  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 83975
	PR 83344
	* resolve.c (resolve_assoc_var): Generate an error if
	target length unknown.
---
 gcc/fortran/resolve.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

-- 
2.7.4

Comments

Thomas Koenig Feb. 1, 2018, 5:36 p.m. | #1
Hi Janne,

> When associating a variable of type character, if the length of the

> target isn't known at compile time, generate an error. See PR 83344

> for more details.

> 

> Regtested on x86_64-pc-linux-gnu, Ok for trunk?


I think this is the most reasonable course of action,
given the circumstances.

OK for trunk. Thanks!

Regards

	Thomas

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 9c8ba86..60b9bc3 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -8634,11 +8634,16 @@  resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
       if (!sym->ts.u.cl)
 	sym->ts.u.cl = target->ts.u.cl;
 
-      if (!sym->ts.u.cl->length && !sym->ts.deferred
-	  && target->expr_type == EXPR_CONSTANT)
-	sym->ts.u.cl->length
-	  = gfc_get_int_expr (gfc_charlen_int_kind,
-			      NULL, target->value.character.length);
+      if (!sym->ts.u.cl->length && !sym->ts.deferred)
+	{
+	  if (target->expr_type == EXPR_CONSTANT)
+	    sym->ts.u.cl->length =
+	      gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+				target->value.character.length);
+	  else
+	    gfc_error ("Not Implemented: Associate target with type character"
+		       " and non-constant length at %L", &target->where);
+	}
     }
 
   /* If the target is a good class object, so is the associate variable.  */