From 2afeb1ca38dbb7c8708272452417426e46b4d6ed Mon Sep 17 00:00:00 2001 From: Mark Eggleston Date: Fri, 8 Nov 2019 14:28:57 +0000 Subject: Allow CHARACTER literals in assignments and data statements. Allows character literals to used to assign values to non-character variables in the same way that Hollerith constants are used. In addition character literals can be used in data statements just like Hollerith constants. Warnings of such use are output to discourage this usage as it is a non-standard legacy feature and must be explicitly enabled. Enabled by -fdec and -fdec-char-conversions. Co-Authored-By: Jim MacArthur From-SVN: r277975 --- gcc/fortran/resolve.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'gcc/fortran/resolve.c') diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 218c2ed..a39b954 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -10689,6 +10689,18 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns) lhs = code->expr1; rhs = code->expr2; + if ((gfc_numeric_ts (&lhs->ts) || lhs->ts.type == BT_LOGICAL) + && rhs->ts.type == BT_CHARACTER + && rhs->expr_type != EXPR_CONSTANT) + { + /* Use of -fdec-char-conversions allows assignment of character data + to non-character variables. This not permited for nonconstant + strings. */ + gfc_error ("Cannot convert %s to %s at %L", gfc_typename (rhs), + gfc_typename (lhs), &rhs->where); + return false; + } + /* Handle the case of a BOZ literal on the RHS. */ if (rhs->ts.type == BT_BOZ) { -- cgit v1.1