Commit 040ca4b3 by Jason Merrill Committed by Jason Merrill

re PR c++/7046 (#pragma pack(1) context evaluated at point of instantiation…

re PR c++/7046 (#pragma pack(1) context evaluated at point of instantiation rather than declaration)

	PR c++/7046
	* class.c (finish_struct): Store maximum_field_alignment in
	TYPE_PRECISION.
	* pt.c (instantiate_class_template): Set maximum_field_alignment.

From-SVN: r153959
parent 2395cd2e
2009-11-05 Jason Merrill <jason@redhat.com> 2009-11-05 Jason Merrill <jason@redhat.com>
PR c++/7046
* class.c (finish_struct): Store maximum_field_alignment in
TYPE_PRECISION.
* pt.c (instantiate_class_template): Set maximum_field_alignment.
PR c++/34870 PR c++/34870
* name-lookup.c (arg_assoc_class): Call complete_type. * name-lookup.c (arg_assoc_class): Call complete_type.
* pt.c (instantiate_class_template): Call uses_template_parms * pt.c (instantiate_class_template): Call uses_template_parms
......
...@@ -5516,6 +5516,9 @@ finish_struct (tree t, tree attributes) ...@@ -5516,6 +5516,9 @@ finish_struct (tree t, tree attributes)
if (DECL_PURE_VIRTUAL_P (x)) if (DECL_PURE_VIRTUAL_P (x))
VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x); VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
complete_vars (t); complete_vars (t);
/* Remember current #pragma pack value. */
TYPE_PRECISION (t) = maximum_field_alignment;
} }
else else
finish_struct_1 (t); finish_struct_1 (t);
......
...@@ -7352,6 +7352,7 @@ instantiate_class_template (tree type) ...@@ -7352,6 +7352,7 @@ instantiate_class_template (tree type)
tree typedecl; tree typedecl;
tree pbinfo; tree pbinfo;
tree base_list; tree base_list;
unsigned int saved_maximum_field_alignment;
if (type == error_mark_node) if (type == error_mark_node)
return error_mark_node; return error_mark_node;
...@@ -7412,6 +7413,9 @@ instantiate_class_template (tree type) ...@@ -7412,6 +7413,9 @@ instantiate_class_template (tree type)
push_deferring_access_checks (dk_no_deferred); push_deferring_access_checks (dk_no_deferred);
push_to_top_level (); push_to_top_level ();
/* Use #pragma pack from the template context. */
saved_maximum_field_alignment = maximum_field_alignment;
maximum_field_alignment = TYPE_PRECISION (pattern);
SET_CLASSTYPE_INTERFACE_UNKNOWN (type); SET_CLASSTYPE_INTERFACE_UNKNOWN (type);
...@@ -7827,6 +7831,7 @@ instantiate_class_template (tree type) ...@@ -7827,6 +7831,7 @@ instantiate_class_template (tree type)
perform_typedefs_access_check (pattern, args); perform_typedefs_access_check (pattern, args);
perform_deferred_access_checks (); perform_deferred_access_checks ();
pop_nested_class (); pop_nested_class ();
maximum_field_alignment = saved_maximum_field_alignment;
pop_from_top_level (); pop_from_top_level ();
pop_deferring_access_checks (); pop_deferring_access_checks ();
pop_tinst_level (); pop_tinst_level ();
......
2009-11-05 Jason Merrill <jason@redhat.com> 2009-11-05 Jason Merrill <jason@redhat.com>
PR c++/7046
* g++.dg/abi/pragma-pack1.C: New.
PR c++/34870 PR c++/34870
* g++.dg/lookup/koenig7.C: New. * g++.dg/lookup/koenig7.C: New.
......
// PR c++/7046
extern "C" int printf (const char *, ...);
#pragma pack(4)
template <typename X >
struct T
{
char x1; /* Usually 3 padding bytes are added after x1 member. */
int x2;
};
template <class T>
int f()
{
struct A { char i1; int i2; };
return sizeof (A);
}
#pragma pack(1)
template struct T<int>; /* T<int> is instantiated here */
template int f<int>();
#pragma pack(4)
template struct T<float>; /* T<float> is instantiated here */
template int f<double>();
int main()
{
printf("sizeof T<int> = %d\n", sizeof(T<int>));
printf("sizeof T<float> = %d\n", sizeof(T<float>));
printf("f<int>() = %d\n", f<int>());
printf("f<float>() = %d\n", f<float>());
return (sizeof(T<int>) != sizeof(T<float>)
|| f<int>() != f<float>());
}
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