const_string = get_array_ctor_strlen (&outer_loop->pre, c,
&ss_info->string_length);
force_new_cl = true;
+
+ /* Initialize "len" with string length for bounds checking. */
+ if ((gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)
+ && !typespec_chararray_ctor
+ && ss_info->string_length)
+ {
+ gfc_se length_se;
+
+ gfc_init_se (&length_se, NULL);
+ gfc_add_modify (&length_se.pre, first_len_val,
+ fold_convert (TREE_TYPE (first_len_val),
+ ss_info->string_length));
+ ss_info->string_length = gfc_evaluate_now (ss_info->string_length,
+ &length_se.pre);
+ gfc_add_block_to_block (&outer_loop->pre, &length_se.pre);
+ gfc_add_block_to_block (&outer_loop->post, &length_se.post);
+ }
}
/* Complex character array constructors should have been taken care of
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-fcheck=bounds -g" }
+! { dg-output "At line 18 .*" }
+! { dg-shouldfail "Different CHARACTER lengths (32/0) in array constructor" }
+!
+! PR fortran/70231 - CHARACTER lengths in array constructors
+
+program p
+ implicit none
+ integer, parameter :: char_len = 32
+ integer :: l = 0
+ character(char_len) :: ch = "a"
+ character(char_len), allocatable :: ch_array(:), res1(:), res2(:)
+
+ allocate(ch_array(0))
+ res1 = [ ch_array, ch ] ! was false positive
+ print *, res1
+ res2 = [[ch_array, ch(1:l)], ch(1:l)] ! was false negative on x86
+ print *, res2
+end