Given the code below, gcc emits the following error:
error: attempt to take address of bit-field structure member 'MyClass::field1'
This compiles fine with Sun's CC, IBM's xlC, and Comeau. The C++ 2003 standard
mentions in 9.6p2 that a non-const reference can't be bound to a bit field, but
that a const reference can be (although it's actually bound to a temporary
initialized with a copy of the bit field rather than the field itself) so I
expect the below code to work fine.
// Code
class MyClass
{
public:
MyClass() { field1 = 0; };
int field1 : 4;
};
int main()
{
MyClass myClass;
const int &fieldRef1 = myClass.field1;
return 0;
}
--
Summary: Can't take a const-ref to a bit field
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc-bugzilla at daryl dot haresign dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43663