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

            Bug ID: 128971
           Summary: Bug in type promotion rules in conditional expression
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: babokin at gmail dot com
                CC: vsevolod.livinskiy at gmail dot com
  Target Milestone: ---

Created attachment 66272
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66272&action=edit
Reproducer

> cat minimal.cpp
struct S { unsigned int f : 4; };
S s{2};
int main() { return (0UL ? s.f : 0) < -1; }

The four-bit unsigned field can hold only 0 through 15, all representable by
`int`. The [C++17 integral-promotion rule for
bit-fields](https://timsong-cpp.github.io/cppwp/n4659/conv.prom)
therefore selects `int`. The [C++17 conditional-expression
rule](https://timsong-cpp.github.io/cppwp/n4659/expr.cond)
applies the usual arithmetic conversions to the field and the integer zero,
so `(0UL ? s.f : 0)` has type `int` and value zero. Comparing it with `-1`
must be false.

GCC produces binary, which return 1. Clang returns 0. This looks wrong for GCC.

Reproduces with GCC trunk and 13.0 as well.

Reply via email to