PR c++/65295
authoraldyh <aldyh@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Mar 2015 18:14:24 +0000 (18:14 +0000)
committeraldyh <aldyh@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Mar 2015 18:14:24 +0000 (18:14 +0000)
* constexpr.c (cxx_eval_constant_expression): Remove assert in
RESULT_DECL handling.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221161 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/pr65295.C [new file with mode: 0644]

index 7fcbcb9..3858590 100644 (file)
@@ -1,3 +1,9 @@
+2015-03-03  Aldy Hernandez  <aldyh@redhat.com>
+
+       PR c++/65295
+       * constexpr.c (cxx_eval_constant_expression): Remove assert in
+       RESULT_DECL handling.
+
 2015-02-26  Marek Polacek  <polacek@redhat.com>
 
        PR c++/65202
index f7e8ce9..1b5f50c 100644 (file)
@@ -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 (file)
index 0000000..c189ee1
--- /dev/null
@@ -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()
+{
+}