diff mbox

C++ PATCH for c++/64080 (constexpr store to non-variable)

Message ID 5480C6A7.1000002@redhat.com
State New
Headers show

Commit Message

Jason Merrill Dec. 4, 2014, 8:40 p.m. UTC
cxx_eval_store_expression was too strict; a store to something where we 
can't figure out which variable it refers to shouldn't ICE, just make 
the expression non-constant.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 796c5ad03637ba9452639262cef57db83cd60cba
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 3 17:15:11 2014 -0500

    	PR c++/64080
    	* constexpr.c (cxx_eval_store_expression): Handle non-decl store
    	targets.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index d18025f..9426d85 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2583,19 +2583,22 @@  cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
 
 	default:
 	  object = probe;
-	  gcc_assert (DECL_P (object));
 	}
     }
 
   /* And then find/build up our initializer for the path to the subobject
      we're initializing.  */
-  tree *valp = ctx->values->get (object);
+  tree *valp;
+  if (DECL_P (object))
+    valp = ctx->values->get (object);
+  else
+    valp = NULL;
   if (!valp)
     {
       /* A constant-expression cannot modify objects from outside the
 	 constant-expression.  */
       if (!ctx->quiet)
-	error ("modification of %qD is not a constant-expression", object);
+	error ("modification of %qE is not a constant-expression", object);
       *non_constant_p = true;
       return t;
     }
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-ref1.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-ref1.C
new file mode 100644
index 0000000..6f88f82
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-ref1.C
@@ -0,0 +1,9 @@ 
+// PR c++/64080
+// { dg-do compile { target c++14 } }
+
+constexpr void foo (int&& i) { i = 0; }
+
+void bar(int&& i)
+{
+  bool b = noexcept(foo(static_cast<int&&>(i)));
+}