This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16376] New: Bit-field promotions
- From: "jsm28 at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Jul 2004 21:26:43 -0000
- Subject: [Bug c++/16376] New: Bit-field promotions
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
[conv.prom] paragraph 3 says that bit-fields are converted to int by the
integral promotions if int can represent all the values of the bit-field.
The following testcase was discussed on the WG14 reflector in January
as illustrating a difference between C compilers (where an unsigned:3
bit-field has a special 3-bit type, so is promoted to int) and C++ compilers
(where an unsigned:3 bit-field has type unsigned, per [class.bit]), but
[conv.prom] wasn't mentioned in that discussion and as far as I can tell
it means that C++ compilers too should promote the unsigned:3 bit-field to
int. If not, what's wrong in my reading of [conv.prom]?
#include <stdio.h>
int main(void){
struct bits {
unsigned int ui3 : 3;
} bits;
int i = -1; /* is a very large positive number as unsigned */
bits.ui3 = 1u;
if( bits.ui3 < i ){
(void)printf("ui3 treated as unsigned, i promoted to unsigned\n");
}else{
(void)printf("ui3 promoted to int (value preserving)\n");
}
return 0;
}
My reading of [conv.prom] is that bits.ui3 should have been promoted to int,
though the statistics from the WG14 reflector were that 29 C++ compilers
converted i to unsigned and only 1 promoted bits.ui3 to int. There are
still differences between C and C++ for bit-fields of types wider than int.
--
Summary: Bit-field promotions
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jsm28 at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16376