@@ -5536,14 +5536,23 @@ gfc_trans_allocate (gfc_code * code)
if (expr3_len == NULL_TREE
&& code->expr3->ts.type == BT_CHARACTER)
{
+ gfc_init_se (&se, NULL);
if (code->expr3->ts.u.cl
&& code->expr3->ts.u.cl->length)
{
- gfc_init_se (&se, NULL);
gfc_conv_expr (&se, code->expr3->ts.u.cl->length);
gfc_add_block_to_block (&block, &se.pre);
expr3_len = gfc_evaluate_now (se.expr, &block);
}
+ else
+ {
+ /* The string_length is not set in the symbol, which prevents
+ it being set in the ts. Deduce it by converting expr3. */
+ gfc_conv_expr (&se, code->expr3);
+ gfc_add_block_to_block (&block, &se.pre);
+ gcc_assert (se.string_length);
+ expr3_len = gfc_evaluate_now (se.string_length, &block);
+ }
gcc_assert (expr3_len);
}
/* For character arrays only the kind's size is needed, because
new file mode 100644
@@ -0,0 +1,24 @@
+! { dg-do run }
+
+program truc
+implicit none
+
+type t_env_table
+ character(len=:), allocatable :: key
+end type
+
+type(t_env_table), dimension(:), allocatable :: environment_table
+
+character(len=:), allocatable :: s
+
+allocate(environment_table(1))
+environment_table(1)%key='tt'
+
+allocate(s, source=environment_table(1)%key)
+
+if ( .not. allocated(s) ) call abort()
+if ( s /= "tt" ) call abort()
+if ( len(s) /= 2 ) call abort()
+!print *, 's:"', s, '" derived:"',environment_table(1)%key,'"'
+
+end program