re PR c++/26670 (attribute((packed)) sometimes not ignored for non-PODs)
authorJason Merrill <jason@gcc.gnu.org>
Tue, 29 Aug 2006 06:55:35 +0000 (02:55 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 29 Aug 2006 06:55:35 +0000 (02:55 -0400)
        PR c++/26670
        * class.c (check_field_decls): Unset TYPE_PACKED (t) if one of the
        fields can't be packed.

From-SVN: r116555

gcc/cp/class.c
gcc/testsuite/g++.dg/ext/packed11.C [new file with mode: 0644]

index 18996a043b8ac10cddbcc3bf9d7f291a767b662d..550edffaaab6a361beba3c711cf06ca919a23e46 100644 (file)
@@ -2906,10 +2906,13 @@ check_field_decls (tree t, tree *access_decls,
       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);
+           {
+             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;
        }
diff --git a/gcc/testsuite/g++.dg/ext/packed11.C b/gcc/testsuite/g++.dg/ext/packed11.C
new file mode 100644 (file)
index 0000000..e75845d
--- /dev/null
@@ -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));