https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112647

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
The standard is clear on this.

In N1570 section 6.5.8 "Relational operators" p3:

If both of the operands have arithmetic type, the usual arithmetic conversions
are
performed.

In section 6.3.1.8 "Usual arithmetic conversions":

<quote>
Otherwise, the integer promotions are performed on both operands. Then the
following rules are applied to the promoted operands:

If both operands have the same type, then no further conversion is needed.
... ...
</quote>

The leading "otherwise" basically means "neither operands have a floating-point
type".

In section 6.3.1.1 "Boolean, characters, and integers" p2 and p3:

<quote>
The following may be used in an expression wherever an int or unsigned int may
be used:

- An object or expression with an integer type (other than int or unsigned int)
whose integer conversion rank is less than or equal to the rank of int and
unsigned int.
- A bit-field of type _Bool, int, signed int, or unsigned int.

If an int can represent all values of the original type (as restricted by the
width, for a bit-field), the value is converted to an int; otherwise, it is
converted to an unsigned int. These are called the integer promotions.

The integer promotions preserve value including sign.
</quote>

Here an int can obviously represent all values of "unsigned isActive : 1" (the
values are 0 and 1), so the value is converted to a int.  And the value
(including sign) is preserved, so the left operand is converted to (int) 1, not
(int) -1.  Now the left operand and the right operand have the same type, so
"both operands have the same type, no further conversion is needed."  Then we
are just evaluating (int)1 > (int)0, resulting 1.

Those words are unchanged (except _Bool is replaced with bool) in N3054.

So GCC does the correct thing.  Not a GCC bug.

Reply via email to