Commit a402c1b1 by Jason Merrill Committed by Jason Merrill

re PR c++/41788 (-Wpacked option changes the layout of packed non-POD structs)

	PR c++/41788
	* class.c (layout_class_type): Set packed_maybe_necessary for packed
	non-PODs.

From-SVN: r156088
parent 1f4a7a48
2010-01-20 Jason Merrill <jason@redhat.com> 2010-01-20 Jason Merrill <jason@redhat.com>
PR c++/41788
* class.c (layout_class_type): Set packed_maybe_necessary for packed
non-PODs.
PR c++/41920 PR c++/41920
* semantics.c (build_lambda_object): Call mark_used on captured * semantics.c (build_lambda_object): Call mark_used on captured
variables. variables.
......
...@@ -5216,6 +5216,11 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -5216,6 +5216,11 @@ layout_class_type (tree t, tree *virtuals_p)
build_decl (input_location, build_decl (input_location,
FIELD_DECL, NULL_TREE, char_type_node)); FIELD_DECL, NULL_TREE, char_type_node));
/* If this is a non-POD, declaring it packed makes a difference to how it
can be used as a field; don't let finalize_record_size undo it. */
if (TYPE_PACKED (t) && !layout_pod_type_p (t))
rli->packed_maybe_necessary = true;
/* Let the back end lay out the type. */ /* Let the back end lay out the type. */
finish_record_layout (rli, /*free_p=*/true); finish_record_layout (rli, /*free_p=*/true);
......
2010-01-20 Jason Merrill <jason@redhat.com> 2010-01-20 Jason Merrill <jason@redhat.com>
PR c++/41788
* g++.dg/abi/packed1.C: New.
PR c++/41920 PR c++/41920
* g++.dg/cpp0x/lambda/lambda-warn1.C: New. * g++.dg/cpp0x/lambda/lambda-warn1.C: New.
......
// PR c++/41788
// { dg-options "-Wpacked" }
// { dg-do run }
extern "C" void abort ();
struct INNER {
virtual int foo() const { return 1; }
} __attribute__ ((packed));
struct OUTER {
char c;
INNER inner;
} __attribute__ ((packed));
int main()
{
OUTER outer;
int s = sizeof(outer);
int o = (char *)&outer.inner - (char *)&outer;
if (s != sizeof (char) + sizeof (void*)
|| o != sizeof (char))
abort ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment