@@ -9043,6 +9043,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
stmtblock_t body;
bool l_is_temp;
bool scalar_to_array;
+ bool alloc_to_alloc;
tree string_length;
int n;
@@ -9156,6 +9157,18 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
else
gfc_conv_expr (&lse, expr1);
+ alloc_to_alloc = expr1->expr_type == EXPR_VARIABLE
+ && expr1->symtree->n.sym->ts.type == BT_DERIVED
+ && expr1->symtree->n.sym->attr.allocatable
+ && expr2->expr_type == EXPR_FUNCTION
+ && expr2->ts.type == BT_DERIVED
+ && expr2->value.function.esym->attr.allocatable;
+ if (alloc_to_alloc)
+ {
+ rse.expr = gfc_build_addr_expr (NULL_TREE, rse.expr);
+ lse.expr = gfc_build_addr_expr (NULL_TREE, lse.expr);;
+ }
+
/* Assignments of scalar derived types with allocatable components
to arrays must be done with a deep copy and the rhs temporary
must have its components deallocated afterwards. */
@@ -9208,7 +9221,8 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
if (lss == gfc_ss_terminator)
{
/* F2003: Add the code for reallocation on assignment. */
- if (flag_realloc_lhs && is_scalar_reallocatable_lhs (expr1))
+ if (flag_realloc_lhs && !alloc_to_alloc
+ && is_scalar_reallocatable_lhs (expr1))
alloc_scalar_allocatable_for_assignment (&block, string_length,
expr1, expr2);