From: Marek Polacek Date: Tue, 20 Mar 2018 18:13:38 +0000 (+0000) Subject: re PR c++/84927 (ICE with NSDMI and reference) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1efb1dc2d893db2fa8f15945d506410aab628b60;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 894a33e5235..c4dd7d11163 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-20 Marek Polacek + + 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 PR c++/84978, ICE with NRVO. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 894bcd0bb3e..1f8ece89730 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 21a16df4884..edef059e7ef 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-20 Marek Polacek + + PR c++/84978, ICE with NRVO. + * g++.dg/opt/nrv19.C: New test. + 2018-03-20 Nathan Sidwell 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 00000000000..385593cc90c --- /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; +}