[C++ PATCH] Propagate TYPE_PACKED to template variants (PR c++/88181)

Jakub Jelinek jakub@redhat.com
Mon Nov 26 20:55:00 GMT 2018


Hi!

On the following patch -fpack-struct forces TYPE_PACKED on all the classes
and their variants, but we then create a variant of a class instantiation
(const) which doesn't have the TYPE_PACKED set and later finalize the
template main variant, but don't propagate that to the already created
variants.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?

2018-11-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/88181
	* class.c (fixup_attribute_variants): Also propagate TYPE_PACKED
	to variants.

	* g++.dg/debug/pr88181.C: New test.

--- gcc/cp/class.c.jj	2018-11-01 13:30:55.805803718 +0100
+++ gcc/cp/class.c	2018-11-26 15:07:59.555553144 +0100
@@ -1951,6 +1951,7 @@ fixup_attribute_variants (tree t)
   unsigned align = TYPE_ALIGN (t);
   bool user_align = TYPE_USER_ALIGN (t);
   bool may_alias = lookup_attribute ("may_alias", attrs);
+  bool packed = TYPE_PACKED (t);
 
   if (may_alias)
     fixup_may_alias (t);
@@ -1968,6 +1969,7 @@ fixup_attribute_variants (tree t)
       else
 	TYPE_USER_ALIGN (variants) = user_align;
       SET_TYPE_ALIGN (variants, valign);
+      TYPE_PACKED (variants) = packed;
       if (may_alias)
 	fixup_may_alias (variants);
     }
--- gcc/testsuite/g++.dg/debug/pr88181.C.jj	2018-11-26 15:17:56.272765972 +0100
+++ gcc/testsuite/g++.dg/debug/pr88181.C	2018-11-26 15:17:44.745955023 +0100
@@ -0,0 +1,29 @@
+// PR c++/88181
+// { dg-do compile }
+// { dg-options "-fpack-struct -g -std=c++11" }
+
+template <typename T> struct A { typedef T B; };
+template <typename...> class C;
+template <typename e> struct D { constexpr D (e) {} };
+template <int, typename...> struct E;
+template <int N, typename T, typename... U>
+struct E<N, T, U...> : E<1, U...>, D<T> {
+  constexpr E (T x, U... y) : E<1, U...>(y...), D<T>(x) {}
+};
+template <int N, typename T> struct E<N, T> : D<T> {
+  constexpr E (T x) : D<T>(x) {}
+};
+template <typename T, typename U> struct C<T, U> : E<0, T, U> {
+  constexpr C (T x, U y) : E<0, T, U>(x, y) {}
+  void operator= (typename A<const C>::B);
+};
+struct F {};
+struct G {};
+
+int
+main ()
+{
+  F f;
+  G g;
+  constexpr C<F, G> c(f, g);
+}

	Jakub



More information about the Gcc-patches mailing list