}
}
- /* Check string lengths if applicable. The check is only really added
- to the output code if -fbounds-check is enabled. */
- if (expr1->ts.type == BT_CHARACTER && expr2->expr_type != EXPR_NULL)
- {
- gcc_assert (expr2->ts.type == BT_CHARACTER);
- gcc_assert (strlen_lhs && strlen_rhs);
- gfc_trans_same_strlen_check ("pointer assignment", &expr1->where,
- strlen_lhs, strlen_rhs, &block);
- }
-
/* If rank remapping was done, check with -fcheck=bounds that
the target is at least as large as the pointer. */
if (rank_remap && (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS))
gfc_add_modify (&block, tmp, build_zero_cst (TREE_TYPE (tmp)));
}
+ /* Check string lengths if applicable. The check is only really added
+ to the output code if -fbounds-check is enabled. */
+ if (expr1->ts.type == BT_CHARACTER && expr2->expr_type != EXPR_NULL)
+ {
+ gcc_assert (expr2->ts.type == BT_CHARACTER);
+ gcc_assert (strlen_lhs && strlen_rhs);
+ gfc_trans_same_strlen_check ("pointer assignment", &expr1->where,
+ strlen_lhs, strlen_rhs, &block);
+ }
+
gfc_add_block_to_block (&block, &lse.post);
if (rank_remap)
gfc_add_block_to_block (&block, &rse.post);
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-fcheck=bounds" }
+!
+! PR fortran/87045 - pointer to array of character
+! Contributed by Valery Weber
+! This used to give an invalid run-time error
+
+program test
+ character(:), dimension(:), allocatable, target :: t
+ character(:), pointer, dimension(:) :: p
+ allocate( character(3) :: t(2) )
+ t(1) = "abc"
+ t(2) = "123"
+ p => t
+ if (size (p) /= 2) stop 1
+ if (len (p) /= 3) stop 2
+ if (p(1) /= "abc") stop 3
+ if (p(2) /= "123") stop 4
+end program test