diff mbox

PR c++/65295: Allow return-value optimization for constexpr's

Message ID 54F5FAC4.5070300@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez March 3, 2015, 6:17 p.m. UTC
In constexpr handling, we can request an rval for a return-value both by 
an invisible reference and by virtue of named return value optimization.

Fixed by removing the assert.

Approved by Jason off-line.

Committed to mainline.
commit 1a8fdc708eeab70adc237193febf5f8db1eab995
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Mar 3 10:13:14 2015 -0800

    	PR c++/65295
    	* constexpr.c (cxx_eval_constant_expression): Remove assert in
    	RESULT_DECL handling.
diff mbox

Patch

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index f7e8ce9..1b5f50c 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 0000000..c189ee1
--- /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()
+{
+}