re PR c++/65690 (typedef alignment lost since r219705)
authorJakub Jelinek <jakub@redhat.com>
Thu, 9 Apr 2015 20:11:44 +0000 (22:11 +0200)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 9 Apr 2015 20:11:44 +0000 (16:11 -0400)
PR c++/65690
  * tree.c (cp_build_qualified_type_real): Copy TYPE_ALIGN and
TYPE_USER_ALIGN.

From-SVN: r221960

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/c-c++-common/attr-aligned-1.c [new file with mode: 0644]

index 065cd75f3589effd931c8593751a9cde6aa9b754..91ddee0233c105b3f2fe723b454f48186cf16140 100644 (file)
@@ -1,5 +1,9 @@
 2015-04-09  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/65690
+       * tree.c (cp_build_qualified_type_real): Copy TYPE_ALIGN and
+       TYPE_USER_ALIGN.
+
        PR c++/65690
        * tree.c (build_cplus_array_type): Layout type before variants are
        set, but copy over TYPE_SIZE and TYPE_SIZE_UNIT from the main
index 6802909a2bff835f3f4cb3ecd6997460fadc3418..71c84ae38ef7a09c76f5de40ee1ed3dac7050eab 100644 (file)
@@ -1079,6 +1079,8 @@ cp_build_qualified_type_real (tree type,
            {
              t = build_variant_type_copy (t);
              TYPE_NAME (t) = TYPE_NAME (type);
+             TYPE_ALIGN (t) = TYPE_ALIGN (type);
+             TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
            }
        }
 
diff --git a/gcc/testsuite/c-c++-common/attr-aligned-1.c b/gcc/testsuite/c-c++-common/attr-aligned-1.c
new file mode 100644 (file)
index 0000000..671e86b
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR c++/65690 */
+/* { dg-do run } */
+
+typedef double T[4][4] __attribute__((aligned (2 * __alignof__ (double))));
+void foo (const T);
+struct S { T s; };
+
+int
+main ()
+{
+  if (__alignof__ (struct S) != 2 * __alignof__ (double)
+      || __alignof__ (T) != 2 * __alignof__ (double)
+      || __alignof__ (const struct S) != 2 * __alignof__ (double)
+      || __alignof__ (const T) != 2 * __alignof__ (double))
+    __builtin_abort ();
+  return 0;
+}
+
+#if defined(__cplusplus) && __cplusplus >= 201103L
+static_assert (alignof (S) == 2 * alignof (double), "alignment of S");
+static_assert (alignof (T) == 2 * alignof (double), "alignment of T");
+static_assert (alignof (const S) == 2 * alignof (double), "alignment of const S");
+static_assert (alignof (const T) == 2 * alignof (double), "alignment of const T");
+#endif