Hi Mark,

I have a question about your patch for PR c++/26534.  In particular,
you added to standard_conversion in call.c the following code:

      if (expr)
        {
          tree bitfield_type;
          bitfield_type = is_bitfield_expr_with_lowered_type (expr);
          if (bitfield_type)
            from = bitfield_type;
        }

Now consider the following testcase derived from PR c++/27505 and my
analysis on why it fails.

struct s {
  bool field:8;
};

void
foo (struct s *p)
{
  if (!p->field)
    ;
}

When build_unary_op builds TRUTH_NOT_EXPR, it calls
perform_implicit_conversion to convert p->field to the boolean type.
(FWIW, p->field is expressed as <component_ref <indirect_ref ...>
<field_ref ...>>).  The call to perform_implicit_conversion eventually
gets to standard_conversion.  The code fragment of standard_conversion
shown above changes FROM to the boolean_type.  Since TO is also the
boolean type, no conversion happens, causing
perform_implicit_conversion to return the original expression, which
is of INTEGER_TYPE.

invert_truthvalue, called from cp/typeck.c:3969, expects nothing but
expressions of BOOLEAN_TYPE, so it ICEs at fold-const.c:3165.

Now, is the code in standard_conversion meant to be an optimization or
something that's required for language conformance?  If the latter is
the case, can we somehow force a conversion?

Thanks,

Kazu Hirata

Reply via email to