PATCH: zero-width bitfield test

RDBrown@mira.net RDBrown@mira.net
Thu Oct 5 14:36:00 GMT 2000


New test for existing zero-width bitfield behaviour.

2000-10-06  Rodney Brown  <RodneyBrown@mynd.com>
	gcc.dg/.bf-0w1.c: New test zero-width bitfields.

*** /dev/null	Thu Jul  6 03:49:51 2000
--- gcc/testsuite/gcc.dg/bf-0w1.c	Fri Oct  6 18:33:28 2000
***************
*** 0 ****
--- 1,66 ----
+ /* Copyright 2000 Free Software Foundation, Inc.
+    Contributed by Rodney Brown 2000-10-06 */
+ 
+ /* Assert the current behaviour with bitfields.
+    viz, sizeof a struct containing only a zero width bitfield is zero.
+    sizeof a struct containing only a bitfield of a given type is the
+    sizeof that type - with a caveat for constructed long longs.
+    sizeof a struct containing two copies of a bitfield of a given type
+    separated by a zero width bitfield is twice that of a struct containing
+    one copy.
+    Bitfields are documented in ISO 9888:1990 6.5.2.1 "Structure and Union
+    specifiers".
+    With -pedantic-errors this gives the following :-
+    struct has no named members
+    bit-field `((anonymous))' type invalid in ANSI C
+    bit-field `a_dsi' type invalid in ANSI C
+    bit-field `a_dsi' type invalid in ANSI C
+    ...
+    "A bit-field shall have a type that is a qualified or unqualified version
+    of one of int, unsigned int or signed int."
+    */
+ /* { dg-do compile } */
+ /* { dg-options "" } */
+ 
+ #define check_bitfld(bf,type) \
+ struct bf##_0 { \
+   type : 0; \
+ }; \
+ struct bf##_1 { \
+   type a_##bf : 1; \
+ }; \
+ struct bf##_2 { \
+   type a_##bf : 1; \
+   type   : 0; \
+   type b_##bf : 1; \
+ }; \
+ char bf##_check[1 - 2*(sizeof(struct bf##_0) != 0 \
+    || sizeof(struct bf##_1) * 2 != sizeof(struct bf##_2) \
+    || (sizeof(struct bf##_1) != sizeof(type) \
+       && (sizeof(type) != sizeof(long long) \
+ 	 || sizeof(struct bf##_1) != sizeof(long))))]
+ 
+ check_bitfld(dc,char);		/* dc for default char */
+ check_bitfld(sc,signed char);
+ check_bitfld(uc,unsigned char);
+ check_bitfld(ds,short);
+ check_bitfld(ss,signed short);
+ check_bitfld(us,unsigned short);
+ check_bitfld(dsi,short int);
+ check_bitfld(ssi,signed short int);
+ check_bitfld(usi,unsigned short int);
+ check_bitfld(di,int);
+ check_bitfld(si,signed int);
+ check_bitfld(ui,unsigned int);
+ check_bitfld(dl,long);
+ check_bitfld(sl,signed long);
+ check_bitfld(ul,unsigned long);
+ check_bitfld(dli,long int);
+ check_bitfld(sli,signed long int);
+ check_bitfld(uli,unsigned long int);
+ check_bitfld(dll,long long);
+ check_bitfld(sll,signed long long);
+ check_bitfld(ull,unsigned long long);
+ check_bitfld(dlli,long long int );
+ check_bitfld(slli,signed long long int );
+ check_bitfld(ulli,unsigned long long int );


More information about the Gcc-patches mailing list