aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2017-06-19 16:55:21 -0400
committerJason Merrill <jason@gcc.gnu.org>2017-06-19 16:55:21 -0400
commitecc5761533690734622d57cbe25914c44d7913e1 (patch)
treee8b221007b794ca5c28e26c8c6aa77d79c8d2e01
parent5ec046c03624e39858314bd35eb0c06f8e63bd28 (diff)
downloadgcc-ecc5761533690734622d57cbe25914c44d7913e1.zip
gcc-ecc5761533690734622d57cbe25914c44d7913e1.tar.gz
gcc-ecc5761533690734622d57cbe25914c44d7913e1.tar.bz2
PR c++/80829 - ICE with constexpr copy of base subobject.
* constexpr.c (clear_no_implicit_zero): New. (cxx_eval_call_expression): Call it. From-SVN: r249386
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c17
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-base5.C15
3 files changed, 37 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b80d373..ff4280a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-19 Jason Merrill <jason@redhat.com>
+
+ PR c++/80829 - ICE with constexpr copy of base subobject.
+ * constexpr.c (clear_no_implicit_zero): New.
+ (cxx_eval_call_expression): Call it.
+
2017-06-19 Nathan Sidwell <nathan@acm.org>
PR c++/81124
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 569a247..5a57452 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1394,6 +1394,21 @@ cxx_eval_internal_function (const constexpr_ctx *ctx, tree t,
return t;
}
+/* Clean CONSTRUCTOR_NO_IMPLICIT_ZERO from CTOR and its sub-aggregates. */
+
+static void
+clear_no_implicit_zero (tree ctor)
+{
+ if (CONSTRUCTOR_NO_IMPLICIT_ZERO (ctor))
+ {
+ CONSTRUCTOR_NO_IMPLICIT_ZERO (ctor) = false;
+ tree elt; unsigned HOST_WIDE_INT idx;
+ FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, elt)
+ if (TREE_CODE (elt) == CONSTRUCTOR)
+ clear_no_implicit_zero (elt);
+ }
+}
+
/* Subroutine of cxx_eval_constant_expression.
Evaluate the call expression tree T in the context of OLD_CALL expression
evaluation. */
@@ -1697,7 +1712,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
/* The result of a constexpr function must be completely initialized. */
if (TREE_CODE (result) == CONSTRUCTOR)
- CONSTRUCTOR_NO_IMPLICIT_ZERO (result) = false;
+ clear_no_implicit_zero (result);
pop_cx_call_context ();
return unshare_constructor (result);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-base5.C
new file mode 100644
index 0000000..84700bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base5.C
@@ -0,0 +1,15 @@
+// PR c++/80829
+// { dg-do compile { target c++11 } }
+
+struct A {
+ constexpr A(int a) : _a(a) {}
+ int _a;
+};
+
+struct B : public A {
+ constexpr B(int a) : A(a) {}
+};
+
+int main() {
+ constexpr A a = B(10);
+}