I am a bit surprised but apparently Visual Studio is correct here, if we look at the grammar from section 9.2
of the draft C++11 standard it says:
member-declarator:
declarator virt-specifier-seqopt pure-specifieropt
declarator brace-or-equal-initializeropt
identifieropt attribute-specifier-seqopt: constant-expression
and bit-fields are not allowed to have a brace-or-equal-initializer. It is not clear to me why this restriction exists though. This feels like the first time I realized a in-class initializer makes a class a non-aggregate.
This apparently is a defect:
The grammar for member-declarator (9.2 [class.mem]) does not, but should, allow for a brace-or-equal-initializer on a bit-field declarator.
This issue was apparently also caught before C++11 was finalized as we can see from Issues Found Implementing C++0x:
- (Richard Smith) class.mem: bitfield members cannot have in-class initializers
The grammar does not allow a
brace-or-equal-initializer for a bitfield member. This seems like an
oversight. A brace-or-equal-initializer after a constant- expression
appears to be unambiguous.
clang behavior: clang implements the letter of the standard.
suggested resolution: Change the grammar as follows:
member-declarator:
identifieropt attribute-specifier-seqopt : constant-expression brace-or-equal-initializeropt
but apparently this feel through the cracks.