re PR c++/65295 ([C++1y] constexpr function causes ICE if it returns a local variable...
authorAldy Hernandez <aldyh@redhat.com>
Tue, 3 Mar 2015 18:14:24 +0000 (18:14 +0000)
committerAldy Hernandez <aldyh@gcc.gnu.org>
Tue, 3 Mar 2015 18:14:24 +0000 (18:14 +0000)
PR c++/65295
* constexpr.c (cxx_eval_constant_expression): Remove assert in
RESULT_DECL handling.

From-SVN: r221161

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

index 7fcbcb93df04d46e8d07e88461c3e53ea0afc531..385859093f268f29cb7366692e30be3af6f439e7 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 f7e8ce949f332a4a5612f4c943641d5a2754c4bd..1b5f50cb494bf9fe4b3ca130014326753092e496 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()
+{
+}