aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-02-16 11:44:26 -0500
committerJason Merrill <jason@gcc.gnu.org>2018-02-16 11:44:26 -0500
commit280fa93e667c21e5fd3f3c758939376d35e47223 (patch)
tree409f2ad8311ac1a29281454d4a2015c133791cf1 /gcc
parent9dc20710e8380bdaf03551b45a2234c6d18c6519 (diff)
downloadgcc-280fa93e667c21e5fd3f3c758939376d35e47223.zip
gcc-280fa93e667c21e5fd3f3c758939376d35e47223.tar.gz
gcc-280fa93e667c21e5fd3f3c758939376d35e47223.tar.bz2
PR c++/82764 - C++17 ICE with empty base
* class.c (build_base_field_1): Set DECL_SIZE to zero for empty base. From-SVN: r257745
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/class.c10
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/nsdmi-empty1.C18
3 files changed, 31 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 17af633..141a64f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2018-02-16 Jason Merrill <jason@redhat.com>
+ PR c++/82764 - C++17 ICE with empty base
+ * class.c (build_base_field_1): Set DECL_SIZE to zero for empty base.
+
+2018-02-16 Jason Merrill <jason@redhat.com>
+
PR c++/84421 - type-dependent if constexpr
* semantics.c (finish_if_stmt_cond): Check type_dependent_expression_p.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index e48a04a..296305e 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4216,8 +4216,14 @@ build_base_field_1 (tree t, tree basetype, tree *&next_field)
DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
DECL_FIELD_CONTEXT (decl) = t;
- DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
- DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
+ if (is_empty_class (basetype))
+ /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero. */
+ DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
+ else
+ {
+ DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
+ DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
+ }
SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
SET_DECL_MODE (decl, TYPE_MODE (basetype));
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-empty1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-empty1.C
new file mode 100644
index 0000000..66d94e5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-empty1.C
@@ -0,0 +1,18 @@
+// PR c++/82764
+// { dg-do compile { target c++11 } }
+
+struct Empty {};
+struct Empty2 : Empty {};
+
+struct A : Empty2
+{
+ int x {1};
+ int y {2};
+};
+
+struct B
+{
+ A a {};
+};
+
+B b;