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]

Re: C++ PATCH to check_field_decls for c++/26670


Jason Merrill wrote:
In any case, if we have made the decision not to support this, we should be consistent about it; we shouldn't allow the enclosing class to be marked packed either. This patch clears TYPE_PACKED on the enclosing class if one of the fields can't be packed.

Thinking about this more, it occurred to me that we don't want to clear TYPE_PACKED until all the fields have been processed; if the user requested packing we should pack all the individual fields that we can even if we can't mark the whole type as packed.


Tested x86_64-pc-linux-gnu, applied to trunk. Combined patch also applied to 4.1 branch.

2006-08-30  Jason Merrill  <jason@redhat.com>

	PR c++/26670
	* class.c (check_field_decls): Don't unset TYPE_PACKED until all
	the fields have been processed.

Index: class.c
===================================================================
*** class.c	(revision 116555)
--- class.c	(working copy)
*************** check_field_decls (tree t, tree *access_
*** 2795,2800 ****
--- 2795,2801 ----
    tree *next;
    bool has_pointers;
    int any_default_members;
+   int cant_pack = 0;
  
    /* Assume there are no access declarations.  */
    *access_decls = NULL_TREE;
*************** check_field_decls (tree t, tree *access_
*** 2911,2917 ****
  		(0,
  		 "ignoring packed attribute because of unpacked non-POD field %q+#D",
  		 x);
! 	      TYPE_PACKED (t) = 0;
  	    }
  	  else if (TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)
  	    DECL_PACKED (x) = 1;
--- 2912,2918 ----
  		(0,
  		 "ignoring packed attribute because of unpacked non-POD field %q+#D",
  		 x);
! 	      cant_pack = 1;
  	    }
  	  else if (TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)
  	    DECL_PACKED (x) = 1;
*************** check_field_decls (tree t, tree *access_
*** 3038,3043 ****
--- 3039,3047 ----
  		 "  but does not override %<operator=(const %T&)%>", t);
      }
  
+   /* If any of the fields couldn't be packed, unset TYPE_PACKED.  */
+   if (cant_pack)
+     TYPE_PACKED (t) = 0;
  
    /* Check anonymous struct/anonymous union fields.  */
    finish_struct_anon (t);

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