[C++ patch] typedef'd bitfields

Nathan Sidwell nathan@codesourcery.com
Tue Dec 18 03:17:00 GMT 2001


Nathan Sidwell wrote:


>                        Name: bitfield-2.patch
>    bitfield-2.patch    Type: unspecified type (application/octet-stream)
>                    Encoding: base64
Aarg! I seem to have come over all binary again. Here they are in a readable
manner.


-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
-------------- next part --------------
// { dg-do run }
// { dg-options "-ansi -pedantic-errors -funsigned-bitfields" }

// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Dec 2001 <nathan@nathan@codesourcery.com>

typedef int Int;
typedef signed int SInt;
typedef unsigned int UInt;

struct A
{
  SInt bitS : 1;	// signed
  UInt bitU : 1;	// unsigned
  Int bit : 1;		// signedness by -f{signed,unsigned}-bitfields
};

int main ()
{
  A a;

  a.bitS = 1;
  a.bitU = 1;
  a.bit = 1;

  if (a.bitS != -1)
    return 1;
  if (a.bitU != 1)
    return 2;
  if (a.bit != 1)
    return 3;

  return 0;
}
-------------- next part --------------
// { dg-do run }
// { dg-options "-ansi -pedantic-errors -fsigned-bitfields" }

// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Dec 2001 <nathan@nathan@codesourcery.com>

typedef int Int;
typedef signed int SInt;
typedef unsigned int UInt;

struct A
{
  SInt bitS : 1;	// signed
  UInt bitU : 1;	// unsigned
  Int bit : 1;		// signedness by -f{signed,unsigned}-bitfields
};

int main ()
{
  A a;

  a.bitS = 1;
  a.bitU = 1;
  a.bit = 1;

  if (a.bitS != -1)
    return 1;
  if (a.bitU != 1)
    return 2;
  if (a.bit != -1)
    return 3;

  return 0;
}
-------------- next part --------------
2001-12-17  Nathan Sidwell  <nathan@codesourcery.com>

	* decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs,
	remove incorrect comment. Move #if 0'd code to common path. Use
	IMPLICIT_TYPENAME_P. Simplify & reformat ARRAY_TYPE duplication.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.842
diff -c -3 -p -r1.842 decl.c
*** decl.c	2001/12/16 16:06:58	1.842
--- decl.c	2001/12/17 22:52:29
*************** grokdeclarator (declarator, declspecs, d
*** 10051,10057 ****
  		}
  	    }
  	}
-       /* C++ aggregate types.  */
        else if (TREE_CODE (id) == TYPE_DECL)
  	{
  	  if (type)
--- 10051,10056 ----
*************** grokdeclarator (declarator, declspecs, d
*** 10061,10066 ****
--- 10060,10066 ----
  	    {
  	      type = TREE_TYPE (id);
  	      TREE_VALUE (spec) = type;
+ 	      typedef_decl = id;
  	    }
  	  goto found;
  	}
*************** grokdeclarator (declarator, declspecs, d
*** 10075,10084 ****
  	  else
  	    {
  	      type = TREE_TYPE (t);
- #if 0
- 	      /* See the code below that used this.  */
- 	      decl_attr = DECL_ATTRIBUTES (id);
- #endif
  	      typedef_decl = t;
  	    }
  	}
--- 10075,10080 ----
*************** grokdeclarator (declarator, declspecs, d
*** 10089,10094 ****
--- 10085,10095 ----
      found: ;
      }
  
+ #if 0
+   /* See the code below that used this.  */
+   if (typedef_decl)
+     decl_attr = DECL_ATTRIBUTES (typedef_decl);
+ #endif
    typedef_type = type;
  
    /* No type at all: default to `int', and set DEFAULTED_INT
*************** grokdeclarator (declarator, declspecs, d
*** 10135,10141 ****
        type = integer_type_node;
      }
    
!   if (type && TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type))
      {
        /* The implicit typename extension is deprecated and will be
  	 removed.  Warn about its use now.  */
--- 10136,10142 ----
        type = integer_type_node;
      }
    
!   if (type && IMPLICIT_TYPENAME_P (type))
      {
        /* The implicit typename extension is deprecated and will be
  	 removed.  Warn about its use now.  */
*************** grokdeclarator (declarator, declspecs, d
*** 11192,11207 ****
  
    /* Detect the case of an array type of unspecified size
       which came, as such, direct from a typedef name.
!      We must copy the type, so that each identifier gets
!      a distinct type, so that each identifier's size can be
!      controlled separately by its own initializer.  */
  
!   if (type != 0 && typedef_type != 0
!       && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
        && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
!     {
!       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
!     }
  
    /* Detect where we're using a typedef of function type to declare a
       function. last_function_parms will not be set, so we must create
--- 11193,11205 ----
  
    /* Detect the case of an array type of unspecified size
       which came, as such, direct from a typedef name.
!      We must copy the type, so that the array's domain can be
!      individually set by the object's initializer.  */
  
!   if (type && typedef_type
!       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
        && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
!     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
  
    /* Detect where we're using a typedef of function type to declare a
       function. last_function_parms will not be set, so we must create


More information about the Gcc-bugs mailing list