public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] PR c++/65295: Allow return-value optimization for constexpr's
@ 2015-03-03 18:17 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2015-03-03 18:17 UTC (permalink / raw)
  To: gcc-patches, jason merrill

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

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.

[-- Attachment #2: curr --]
[-- Type: text/plain, Size: 1214 bytes --]

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 --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()
+{
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-03 18:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-03 18:17 [patch] PR c++/65295: Allow return-value optimization for constexpr's Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).