This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/40751 (can't change alignment of enum)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 21 Jan 2016 15:24:03 -0500
- Subject: C++ PATCH for c++/40751 (can't change alignment of enum)
- Authentication-results: sourceware.org; auth=none
The problem here was that when copy_type_enum updates the size and
alignment of the enum to match its underlying type, it was clobbering
any explicit alignment. I've fixed similar issues in other places, but
this one needed the update as well.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 0dc9dc45a5a9d2a0efc7456a72e13dab38551d4c
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jan 21 14:22:05 2016 -0500
PR c++/40751
PR c++/64987
* decl.c (copy_type_enum): Respect TYPE_USER_ALIGN.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d995654..020e9bd 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13030,8 +13030,12 @@ copy_type_enum (tree dst, tree src)
TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
SET_TYPE_MODE (dst, TYPE_MODE (src));
TYPE_PRECISION (t) = TYPE_PRECISION (src);
- TYPE_ALIGN (t) = TYPE_ALIGN (src);
- TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
+ unsigned valign = TYPE_ALIGN (src);
+ if (TYPE_USER_ALIGN (t))
+ valign = MAX (valign, TYPE_ALIGN (t));
+ else
+ TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
+ TYPE_ALIGN (t) = valign;
TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
}
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas5.C b/gcc/testsuite/g++.dg/cpp0x/alignas5.C
new file mode 100644
index 0000000..2820ca7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alignas5.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert(X,#X)
+
+enum alignas(16) E {};
+SA(alignof(E) == 16);