From bf66b9b45c6cf6bccd2791d7c091759b2ad35437 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Tue, 3 Mar 2015 18:14:24 +0000 Subject: [PATCH] re PR c++/65295 ([C++1y] constexpr function causes ICE if it returns a local variable bigger than 16 bytes) PR c++/65295 * constexpr.c (cxx_eval_constant_expression): Remove assert in RESULT_DECL handling. From-SVN: r221161 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 4 ++-- gcc/testsuite/g++.dg/pr65295.C | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr65295.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7fcbcb93df0..385859093f2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-03-03 Aldy Hernandez + + PR c++/65295 + * constexpr.c (cxx_eval_constant_expression): Remove assert in + RESULT_DECL handling. + 2015-02-26 Marek Polacek PR c++/65202 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index f7e8ce949f3..1b5f50cb494 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2955,8 +2955,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, if (lval) return t; /* We ask for an rvalue for the RESULT_DECL when indirecting - through an invisible reference. */ - gcc_assert (DECL_BY_REFERENCE (t)); + through an invisible reference, or in named return value + optimization. */ return (*ctx->values->get (t)); case VAR_DECL: diff --git a/gcc/testsuite/g++.dg/pr65295.C b/gcc/testsuite/g++.dg/pr65295.C new file mode 100644 index 00000000000..c189ee1369f --- /dev/null +++ b/gcc/testsuite/g++.dg/pr65295.C @@ -0,0 +1,20 @@ +// { dg-do compile } +// { dg-options "-std=c++1y" } + +struct arr { + constexpr arr() : elem() { } + char elem[17]; +}; + +constexpr +arr f() +{ + arr result; + return result; +} + +constexpr arr a { f() }; + +int main() +{ +} -- 2.30.2