From c88169089283a22360c6a9eacbc9a3345c82598a Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sun, 19 Mar 2017 22:22:36 -0400 Subject: [PATCH] PR c++/80077 - error with constexpr and -fno-elide-constructors. * constexpr.c (cxx_eval_call_expression): Set ctx->call while expanding trivial constructor. From-SVN: r246272 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 5 +++-- gcc/testsuite/g++.dg/cpp0x/constexpr-trivial3.C | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-trivial3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7d2a56a0df8..a7248d93ca3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-03-19 Jason Merrill + + PR c++/80077 - error with constexpr and -fno-elide-constructors. + * constexpr.c (cxx_eval_call_expression): Set ctx->call while + expanding trivial constructor. + 2017-03-17 Jason Merrill PR c++/78345 - ICE initializing array from lambda. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 4136b349282..3ca35607181 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1478,7 +1478,8 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, else op = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (op)), op); tree set = build2 (MODIFY_EXPR, TREE_TYPE (op), op, init); - return cxx_eval_constant_expression (ctx, set, lval, + new_ctx.call = &new_call; + return cxx_eval_constant_expression (&new_ctx, set, lval, non_constant_p, overflow_p); } } @@ -1496,7 +1497,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, } /* If in direct recursive call, optimize definition search. */ - if (ctx && ctx->call && ctx->call->fundef->decl == fun) + if (ctx && ctx->call && ctx->call->fundef && ctx->call->fundef->decl == fun) new_call.fundef = ctx->call->fundef; else { diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-trivial3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-trivial3.C new file mode 100644 index 00000000000..6833cd3ab80 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-trivial3.C @@ -0,0 +1,6 @@ +// PR c++/80077 +// { dg-do compile { target c++11 } } +// { dg-options -fno-elide-constructors } + +struct X_t { X_t() = default; }; +constexpr X_t x = X_t();