[Bug c++/71792] deducing type from bitfield leads to overflow

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Dec 3 08:06:22 GMT 2021


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine for the testcase which is simple:
class some_class
{
public:
  unsigned int np              : 4;
  unsigned int nc              : 8;
  unsigned int nc0             : 1;
};

template<bool what>
static void test_bug (const some_class &mp) {
  if (what) {
    int t = 0;
    for (auto i = mp.nc0; i < mp.nc; i++) {
      if (t != i) __builtin_abort ();
      t++;
    }
  }
}

static void test_ok (const some_class &mp) {
  int t = 0;
  for (auto i = mp.nc0; i < mp.nc; i++) {
    if (t != i) __builtin_abort ();
    t++;
  }
}

int main ()
{
  some_class mp;
  mp.nc0 = 0;
  mp.nc = 9;
  mp.np = 3;

  test_bug<true> (mp);
  test_ok (mp);

  return 0;
}


More information about the Gcc-bugs mailing list