In the following testcase:
#include <new>
#include <stdlib.h>
#include <stdio.h>
class c1
{
public:
char m1 : 17;
//char m2;
};
void printbytes(void * p, int size)
{
printf("Printing an object on %i bytes\n",size);
for (int i=0; i<size; i++)
printf("Byte %i is %i\n",i, ((char*)p)[i]);
printf("Finish printing\n%d\n", __alignof__(c1));
}
int
main (int argc, char **argv) {
c1 * obj = new c1;
printf("Here\n");
obj->m1 = 1;
//obj->m2 = 1;
printbytes(obj,sizeof(c1));
}
The output is:
Here
Printing an object on 4 bytes
Byte 0 is 1
Byte 1 is 0
Byte 2 is 0
Byte 3 is 0
Finish printing
2
The alignment is 2 bytes, however, according to the ABI the alignment of this
non-POD type should be 1. But, in reality the alignment is 1 because when I add
another char member m2, the output is:
Here
Printing an object on 4 bytes
Byte 0 is 1
Byte 1 is 0
Byte 2 is 0
Byte 3 is 1
Finish printing
2
--
Summary: Wrong alignment of struct members where one member is
bitfield exceeding its type.
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cjain at ca dot ibm dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32210