[Bug c++/16376] Bit-field promotions

joseph at codesourcery dot com gcc-bugzilla@gcc.gnu.org
Sun Apr 23 22:22:00 GMT 2006



------- Comment #4 from joseph at codesourcery dot com  2006-04-23 22:22 -------
Subject: Re:  Bit-field promotions

On Sun, 23 Apr 2006, mmitchel at gcc dot gnu dot org wrote:

> However, my patch was not intended to fix this bug, and only does so by
> accident.   In particular, the last lines of decay_conversion convert the
> expression to the TYPE_MAIN_VARIANT of the limited-precision type, rather than
> to the TYPE_MAIN_VARIANT of the declared type of the bitfield, as I had
> intended, although the original conversion from limited-precision type to
> declared type is present in the expression by this point.
> 
> I am not sure if that original conversion is actually required, given that the
> testsuite is passing with the code in its current state.  In earlier forms of
> the patch, it was definitely required; otherwise, for example, bitfields of
> enumeration type did not have the correct type elsewhere in the compiler.  It
> may be that because of the changes I made to the conversion machinery in
> call.c, this is no longer a problem.

The sort of case where you need to convert to the declared type is

#include <stdlib.h>
struct S {
  unsigned long a : 33, b : 33;
} s = { 1UL << 32, 1UL << 32 };

int
main(void)
{
  if (s.a + s.b != (1UL << 33))
    abort();
}

(supposing 32-bit int, 64-bit long).  But given that C++ doesn't define 
LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS, even if the addition is done on 
the reduced types that might not reliably cause the test to fail.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16376



More information about the Gcc-bugs mailing list