[This started on gcc-patches]
Quoting Richard Guenther <richard.guent...@gmail.com>:

On Sat, Jan 23, 2010 at 2:37 PM, Paolo Bonzini <bonz...@gnu.org> wrote:
On 01/23/2010 01:36 PM, Richard Guenther wrote:
Ugh.  I wonder if we should use _Bool instead of int
if the host compiler supports it.

Then we'd have another share of bugs if someone uses

 bool a = <something evaluating to 2>;
 a &= <something evaluating to 1>;

We do have those already.  I run over this recently:

  bool all_critical_edge_p = true;
  all_critical_edge_p &= e->flags & EDGE_CRITICAL;

with _Bool this would work as expected, with ints it doesn't.  With
C++ it would work as well.

Another option would be to stop using bool - as our bool doesn't have
the same semantics as bool in C++ or _Bool in C99.  Which can
be surprising.

I think a better long-term plan would be to add an option to insert run-time
checks to abort when a integer other than 0 or 1 is converted to bool / _Bool.

We could then use this in gcc builds when enable-checking is active.

Or we could add a warning option for any int -> bool/_Bool conversion, but
this could cost some extra GCC runtime overhead as some places will need to
add some_integer != 0 checks to silence the warning, even though some_integer
might be known to always be either 0 or 1.

Reply via email to