+2019-12-19 Mark Eggleston <mark.eggleston@codethink.com>
+
+ PR fortran/92896
+ * array.c (walk_array_constructor): Replace call to gfc_convert_type
+ with call to gfc_convert_type_warn with new argument set to true.
+ (check_element_type): Replace call to cfg_convert_type with call to
+ gfc_convert_type_warn with new argument set to true.
+ * gfortran.h: Add argument "array" to gfc_convert_type_warn default
+ value set to false.
+ *intrinsic.c (gfc_convert_type_warn): Update description of arguments.
+ Add new argument to argument list. Add check for conversion to numeric
+ or logical from character and array set to true, i.e. if conversion
+ from character is in an array constructor reject it, goto bad.
+
2019-12-19 Jakub Jelinek <jakub@redhat.com>
PR fortran/92977
if (m == MATCH_ERROR)
return m;
}
- else if (!gfc_convert_type (e, ts, 1) && e->ts.type != BT_UNKNOWN)
+ else if (!gfc_convert_type_warn (e, ts, 1, 1, true)
+ && e->ts.type != BT_UNKNOWN)
return MATCH_ERROR;
- }
+ }
return MATCH_YES;
}
return 0;
if (convert)
- return gfc_convert_type(expr, &constructor_ts, 1) ? 0 : 1;
+ return gfc_convert_type_warn (expr, &constructor_ts, 1, 1, true) ? 0 : 1;
gfc_error ("Element in %s array constructor at %L is %s",
gfc_typename (&constructor_ts), &expr->where,
char gfc_type_letter (bt, bool logical_equals_int = false);
gfc_symbol * gfc_get_intrinsic_sub_symbol (const char *);
bool gfc_convert_type (gfc_expr *, gfc_typespec *, int);
-bool gfc_convert_type_warn (gfc_expr *, gfc_typespec *, int, int);
+bool gfc_convert_type_warn (gfc_expr *, gfc_typespec *, int, int,
+ bool array = false);
bool gfc_convert_chartype (gfc_expr *, gfc_typespec *);
int gfc_generic_intrinsic (const char *);
int gfc_specific_intrinsic (const char *);
1 Generate a gfc_error()
2 Generate a gfc_internal_error().
- 'wflag' controls the warning related to conversion. */
+ 'wflag' controls the warning related to conversion.
+
+ 'array' indicates whether the conversion is in an array constructor.
+ Non-standard conversion from character to numeric not allowed if true.
+*/
bool
-gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
+gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag,
+ bool array)
{
gfc_intrinsic_sym *sym;
gfc_typespec from_ts;
&& gfc_compare_types (&expr->ts, ts))
return true;
+ /* If array is true then conversion is in an array constructor where
+ non-standard conversion is not allowed. */
+ if (array && from_ts.type == BT_CHARACTER
+ && (gfc_numeric_ts (ts) || ts->type == BT_LOGICAL))
+ goto bad;
+
sym = find_conv (&expr->ts, ts);
if (sym == NULL)
goto bad;
+2019-12-19 Mark Eggleston <mark.eggleston@codethink.com>
+
+ PR fortran/92896
+ * gfortran.dg/no_char_conversion_in_array_constructor.f90: New test.
+
2019-12-19 Richard Sandiford <richard.sandiford@arm.com>
* gcc.target/aarch64/sve/mixed_size_9.c: New test.
--- /dev/null
+! { dg-do compile }
+! { dg-options "-fdec-char-conversions" }
+
+program p
+ print *, -[integer :: 1, [integer(8) :: '2']] ! { dg-error "Cannot convert" }
+ print *, -[real :: 1, [real(8) :: '2']] ! { dg-error "Cannot convert" }
+ print *, -[complex :: 1, [complex(8) :: '2']] ! { dg-error "Cannot convert" }
+ print *, [logical :: 1, [logical(8) :: '2']] ! { dg-error "Cannot convert" }
+end
+