aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2018-03-20 18:13:38 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2018-03-20 18:13:38 +0000
commit1efb1dc2d893db2fa8f15945d506410aab628b60 (patch)
treecb02f82151fa7f7bd4cef7375f6174ef7a066af4
parentf5f035a336a9a47d326e800e97fe7fbbeede4a99 (diff)
downloadgcc-1efb1dc2d893db2fa8f15945d506410aab628b60.zip
gcc-1efb1dc2d893db2fa8f15945d506410aab628b60.tar.gz
gcc-1efb1dc2d893db2fa8f15945d506410aab628b60.tar.bz2
re PR c++/84927 (ICE with NSDMI and reference)
PR c++/84927 * constexpr.c (cxx_eval_bare_aggregate): Update constructor's flags as we evaluate the elements. (cxx_eval_constant_expression): Verify constructor's flags unconditionally. * g++.dg/cpp1y/nsdmi-aggr9.C: New test. From-SVN: r258691
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c10
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/opt/nrv19.C15
4 files changed, 35 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 894a33e..c4dd7d1 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-03-20 Marek Polacek <polacek@redhat.com>
+
+ PR c++/84978, ICE with NRVO.
+ * constexpr.c (cxx_eval_constant_expression): Handle the case when
+ a RESULT_DECL isn't in the hash map.
+
2018-03-20 Jason Merrill <jason@redhat.com>
PR c++/84978, ICE with NRVO.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 894bcd0..1f8ece8 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4111,7 +4111,15 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
/* We ask for an rvalue for the RESULT_DECL when indirecting
through an invisible reference, or in named return value
optimization. */
- return (*ctx->values->get (t));
+ if (tree *p = ctx->values->get (t))
+ return *p;
+ else
+ {
+ if (!ctx->quiet)
+ error ("%qE is not a constant expression", t);
+ *non_constant_p = true;
+ }
+ break;
case VAR_DECL:
if (DECL_HAS_VALUE_EXPR_P (t))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 21a16df..edef059 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-03-20 Marek Polacek <polacek@redhat.com>
+
+ PR c++/84978, ICE with NRVO.
+ * g++.dg/opt/nrv19.C: New test.
+
2018-03-20 Nathan Sidwell <nathan@acm.org>
PR c++/84962
diff --git a/gcc/testsuite/g++.dg/opt/nrv19.C b/gcc/testsuite/g++.dg/opt/nrv19.C
new file mode 100644
index 0000000..385593c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/nrv19.C
@@ -0,0 +1,15 @@
+// PR c++/84978
+// { dg-do compile }
+
+struct S {
+ void (*fn)();
+ int a[10];
+};
+
+S
+foo ()
+{
+ S s;
+ s.fn ();
+ return s;
+}