typeof and bitfields

Matt Austern austern@apple.com
Fri Jan 14 00:13:00 GMT 2005


Consider the following code:
struct X { int n : 1; };
void foo() { struct X x; typeof(x.n) tmp; }

With 3.3 it compiles both as C and as C++.  With 4.0 it still compiles 
as C++, but it fails when compiled as C with the error message:
foo.c:2: error: 'typeof' applied to a bit-field

This was obviously a deliberate change.  However, I don't see any 
mention about it in the part of the manual that documents typeof.  I 
also can't guess why this should be different in C and in C++, or what 
the rationale for the change might have been in the first place.  Sure, 
applying sizeof or alignof to a bit-field makes no sense.  But typeof?  
X::n has a perfectly good type, as the C++ compiler understands.

I was tempted to just file a bug report, on the grounds that this is a 
regression (an undocumented change in the behavior of a language 
feature that causes some code that used that feature to break), but 
perhaps there's some rationale for the change that I'm just not seeing.

			--Matt



More information about the Gcc mailing list