https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69514
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #5 from kargl at gcc dot gnu.org ---
(In reply to lkrupp from comment #4)
> This patch is a kludge. I don't recommend it. But it does fix at least one
> of the test cases, it passes the test suite, and it might point to a proper
> solution:
>
> Index: arith.c
> ===================================================================
> --- arith.c (revision 239966)
> +++ arith.c (working copy)
> @@ -1326,7 +1326,21 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_e
> for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c))
> {
> if (c->expr->expr_type == EXPR_CONSTANT)
> - rc = eval (op1, c->expr, &r);
> + {
> + /* The conversion *should* be done only if necessary. */
> + gfc_expr temp;
> +
> + temp.expr_type = EXPR_OP;
> + gfc_clear_ts (&temp.ts);
> +
> + temp.value.op.op = INTRINSIC_PLUS; /* Arbitrary */
> + temp.value.op.op1 = op1;
> + temp.value.op.op2 = c->expr;
> +
> + gfc_type_convert_binary (&temp,
> + warn_conversion || warn_conversion_extra);
> +
> + rc = eval (op1, c->expr, &r);
> + }
> else
> rc = reduce_binary_ca (eval, op1, c->expr, &r);
I agree the patch is a kludge. :-)
For a constructor with a typespec, gfortran should probably
walk the constructor and ensure type conversion for numeric
data types. The patch does that.
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c (revision 239797)
+++ gcc/fortran/array.c (working copy)
@@ -1089,6 +1089,7 @@ match_array_cons_element (gfc_constructo
match
gfc_match_array_constructor (gfc_expr **result)
{
+ gfc_constructor *c;
gfc_constructor_base head, new_cons;
gfc_undo_change_set changed_syms;
gfc_expr *expr;
@@ -1194,8 +1195,6 @@ done:
be converted. See PR fortran/67803. */
if (ts.type == BT_CHARACTER)
{
- gfc_constructor *c;
-
c = gfc_constructor_first (head);
for (; c; c = gfc_constructor_next (c))
{
@@ -1218,6 +1217,14 @@ done:
}
}
}
+
+ /* Walk the constructor and ensure type conversion for numeric types.
*/
+ if (gfc_numeric_ts (&ts))
+ {
+ c = gfc_constructor_first (head);
+ for (; c; c = gfc_constructor_next (c))
+ gfc_convert_type (c->expr, &ts, 1);
+ }
}
else
expr = gfc_get_array_expr (BT_UNKNOWN, 0, &where);
Index: gcc/testsuite/gfortran.dg/pr69514.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr69514.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr69514.f90 (working copy)
@@ -0,0 +1,5 @@
+! { dg-do run }
+program foo
+ real, parameter :: x(3) = 2.0 * [real :: 1, 2, 3 ]
+ if (any(x /= [2., 4., 6.])) call abort
+end program foo