This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR 46659 - extend conversion warnings to assignments


On 08/15/2011 07:49 PM, Thomas Koenig wrote:
Am 14.08.2011 22:54, schrieb Tobias Burnus:
Thomas Koenig wrote:
the attached patch extends conversion warnings to assignments.
OK for trunk?

I get now two warnings for:


complex(8), parameter :: z = cmplx (0.5, 0.5)
r = z
end

The problem is that gfc_check_assign is called twice for this, from different code paths

Well, I don't think that this is the problem - the actual warning comes from the calling of the same code path:


a) Call to gfc_check_assign_symbol from add_init_expr_to_sym: This does not print a warning for "z = cmplx(0.5,0.5)" (Side note: There is a conversion from kind=4 to kind=8)

b) Call from gfc_resolve for "r = z"
b.1) gfc_warning call in gfc_check_assign at expr.c:3228 -- the code which you added
b.2) gfc_warning_now call in gfc_convert_type_warn (intrinsic.c:4349), which is called from gfc_check_assign (line 3272).


(b.2) is guarded by
      else if (from_ts.type == ts->type
               || (from_ts.type == BT_INTEGER && ts->type == BT_REAL)
               || (from_ts.type == BT_INTEGER && ts->type == BT_COMPLEX)
               || (from_ts.type == BT_REAL && ts->type == BT_COMPLEX))

while (b.1) uses
  if (rvalue->expr_type == EXPR_CONSTANT
&& (lvalue->ts.type == BT_REAL || lvalue->ts.type == BT_COMPLEX)
&& (rvalue->ts.type == BT_REAL || rvalue->ts.type == BT_COMPLEX))

As written, you should consider changing this to, e.g.,

  if (rvalue->expr_type == EXPR_CONSTANT
&& (lvalue->ts.type == BT_REAL || lvalue->ts.type == BT_COMPLEX)
&& (rvalue->ts.type == rvalue->ts.type))

or at least you should exclude rvalue == BT_COMPLX and lvalue == BT_REAL.


Tobias



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]