memset (&lvalue, '\0', sizeof (gfc_expr));
+ if (sym && sym->attr.pdt_template && comp && comp->initializer)
+ {
+ int i, flag;
+ gfc_expr *param_expr;
+ flag = 0;
+
+ if (comp->as && comp->as->type == AS_EXPLICIT
+ && !(comp->ts.type == BT_DERIVED
+ && comp->ts.u.derived->attr.pdt_template))
+ {
+ /* Are the bounds of the array parameterized? */
+ for (i = 0; i < comp->as->rank; i++)
+ {
+ param_expr = gfc_copy_expr (comp->as->lower[i]);
+ if (gfc_simplify_expr (param_expr, 1)
+ && param_expr->expr_type != EXPR_CONSTANT)
+ flag++;
+ gfc_free_expr (param_expr);
+ param_expr = gfc_copy_expr (comp->as->upper[i]);
+ if (gfc_simplify_expr (param_expr, 1)
+ && param_expr->expr_type != EXPR_CONSTANT)
+ flag++;
+ gfc_free_expr (param_expr);
+ }
+ }
+
+ /* Is the character length parameterized? */
+ if (comp->ts.type == BT_CHARACTER && comp->ts.u.cl->length)
+ {
+ param_expr = gfc_copy_expr (comp->ts.u.cl->length);
+ if (gfc_simplify_expr (param_expr, 1)
+ && param_expr->expr_type != EXPR_CONSTANT)
+ flag++;
+ gfc_free_expr (param_expr);
+ }
+
+ if (flag)
+ {
+ gfc_error ("The component %qs at %L of derived type %qs has "
+ "paramterized type or array length parameters, which is "
+ "not compatible with a default initializer",
+ comp->name, &comp->initializer->where, sym->name);
+ return false;
+ }
+ }
+
lvalue.expr_type = EXPR_VARIABLE;
lvalue.ts = sym->ts;
if (sym->as)
gfc_cleanup_loop (&loop);
}
+ /* Since parameterized components cannot have default initializers,
+ the default PDT constructor leaves them unallocated. Do the
+ allocation now. */
+ if (init_flag && expr1->ts.type == BT_DERIVED
+ && expr1->ts.u.derived->attr.pdt_type
+ && !expr1->symtree->n.sym->attr.allocatable
+ && !expr1->symtree->n.sym->attr.dummy)
+ {
+ gfc_symbol *sym = expr1->symtree->n.sym;
+ tmp = gfc_allocate_pdt_comp (sym->ts.u.derived,
+ sym->backend_decl,
+ sym->as ? sym->as->rank : 0,
+ sym->param_list);
+ gfc_add_expr_to_block (&block, tmp);
+ }
+
return gfc_finish_block (&block);
}
{
tmp = gfc_trans_zero_assign (expr1);
if (tmp)
- return tmp;
+ return tmp;
}
/* Special case copying one array to another. */
{
tmp = gfc_trans_array_copy (expr1, expr2);
if (tmp)
- return tmp;
+ return tmp;
}
/* Special case initializing an array from a constant array constructor. */
implicit none
type :: vec(k)
integer, len :: k=3
- integer :: foo(k)=[1,2,3]
+ integer :: foo(k)
end type vec
contains
elemental function addvv(a,b) result(c)
if (any (c(1)%foo .ne. [13,15,17])) STOP 2
end program test_pdt
! { dg-final { scan-tree-dump-times "__builtin_free" 8 "original" } }
-! { dg-final { scan-tree-dump-times "__builtin_malloc" 9 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_malloc" 8 "original" } }
-! { dg-do run }
+! { dg-do compile }
!
-! Test the fix for PR83611, in which the assignment caused a
-! double free error and the initialization of 'foo' was not done.
+! This originally tested the fix for PR83611, in which the assignment caused a
+! double free error and the initialization of 'foo' was not done. However, the
+! initialization is not conforming (see PR84432 & PR114815) and so this test
+! is now compile only and verifies the error detection. The program part has
+! been deleted.
!
module pdt_m
implicit none
type :: vec(k)
integer, len :: k=3
- integer :: foo(k)=[1,2,3]
+ integer :: foo(k)=[1,2,3] ! { dg-error "not compatible with a default initializer" }
+ character(len = k) :: chr = "ab" ! { dg-error "not compatible with a default initializer" }
end type vec
end module pdt_m
-
-program test_pdt
- use pdt_m
- implicit none
- type(vec) :: u,v
- if (any (u%foo .ne. [1,2,3])) STOP 1
- u%foo = [7,8,9]
- v = u
- if (any (v%foo .ne. [7,8,9])) STOP 2
-end program test_pdt