This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch for PR c/10333


This patch fixes PR c/10333: typeof should be rejected when applied to
bit-fields, just as sizeof is.

Bootstrapped with no regressions on i686-pc-linux-gnu.  Applied to
mainline.

2003-11-29  Joseph S. Myers  <jsm@polyomino.org.uk>

	PR c/10333
	* c-parse.in (typespec_reserved_nonattr): Reject typeof on
	bit-fields.

testsuite:
2003-11-29  Joseph S. Myers  <jsm@polyomino.org.uk>

	PR c/10333
	* gcc.dg/bitfld-7.c: New test.

--- GCC/gcc/c-parse.in.orig	2003-11-26 13:49:04.000000000 +0000
+++ GCC/gcc/c-parse.in	2003-11-29 11:33:51.000000000 +0000
@@ -1375,7 +1375,11 @@ typespec_nonreserved_nonattr:
                 { $$ = get_object_reference ($1); }
 @@end_ifobjc
 	| typeof '(' expr ')'
-		{ skip_evaluation--; $$ = TREE_TYPE ($3); }
+		{ skip_evaluation--;
+		  if (TREE_CODE ($3) == COMPONENT_REF
+		      && DECL_C_BIT_FIELD (TREE_OPERAND ($3, 1)))
+		    error ("`typeof' applied to a bit-field");
+		  $$ = TREE_TYPE ($3); }
 	| typeof '(' typename ')'
 		{ skip_evaluation--; $$ = groktypename ($3); }
 	;
--- GCC/gcc/testsuite/gcc.dg/bitfld-7.c	2002-08-26 16:21:36.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/bitfld-7.c	2003-11-29 11:36:19.000000000 +0000
@@ -0,0 +1,8 @@
+/* Test for rejection of typeof on bit-fields.  PR c/10333.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct { int a:1; } x;
+
+typeof (x.a) z; /* { dg-error "applied to a bit-field" "typeof" } */

-- 
Joseph S. Myers
jsm@polyomino.org.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]