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]

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


In the testcase for 26670, a non-POD class is used as a field in a packed class. We don't support this for some reason I don't remember, dating back to Nathan's change of 2003-07-22.

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.

Tested x86_64-pc-linux-gnu, applied to trunk.


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

	PR c++/26670
	* class.c (check_field_decls): Unset TYPE_PACKED (t) if one of the
	fields can't be packed.

Index: class.c
===================================================================
*** class.c	(revision 116352)
--- class.c	(working copy)
*************** check_field_decls (tree t, tree *access_
*** 2912,2921 ****
        if (TYPE_PACKED (t))
  	{
  	  if (!pod_type_p (type) && !TYPE_PACKED (type))
! 	    warning
! 	      (0,
! 	       "ignoring packed attribute on unpacked non-POD field %q+#D",
! 	       x);
  	  else if (TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)
  	    DECL_PACKED (x) = 1;
  	}
--- 2912,2924 ----
        if (TYPE_PACKED (t))
  	{
  	  if (!pod_type_p (type) && !TYPE_PACKED (type))
! 	    {
! 	      warning
! 		(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;
  	}
Index: /home/jason/ged/ext/packed11.C
===================================================================
*** /home/jason/ged/ext/packed11.C	(revision 0)
--- /home/jason/ged/ext/packed11.C	(revision 0)
***************
*** 0 ****
--- 1,13 ----
+ // PR c++/26670
+ 
+ struct nonpod {
+   nonpod();
+ };
+ 
+ struct nonpod_pack {
+   nonpod n;		      // { dg-warning "ignoring packed attribute" }
+ } __attribute__ ((packed));
+ 
+ struct nonpod_pack2 {
+   nonpod_pack p;	      // { dg-warning "ignoring packed attribute" }
+ } __attribute__ ((packed));

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