PR c++/67813
* constexpr.c (cxx_eval_store_expression): Always use *valp if
set.
From-SVN: r229270
+2015-10-23 Jason Merrill <jason@redhat.com>
+
+ PR c++/67813
+ * constexpr.c (cxx_eval_store_expression): Always use *valp if
+ set.
+
2015-10-22 Jason Merrill <jason@redhat.com>
* call.c (add_template_conv_candidate): Pass DEDUCE_CALL.
{
/* Create a new CONSTRUCTOR in case evaluation of the initializer
wants to modify it. */
- new_ctx.ctor = build_constructor (type, NULL);
if (*valp == NULL_TREE)
- *valp = new_ctx.ctor;
- CONSTRUCTOR_NO_IMPLICIT_ZERO (new_ctx.ctor) = no_zero_init;
+ {
+ *valp = new_ctx.ctor = build_constructor (type, NULL);
+ CONSTRUCTOR_NO_IMPLICIT_ZERO (new_ctx.ctor) = no_zero_init;
+ }
+ else
+ new_ctx.ctor = *valp;
new_ctx.object = target;
}
--- /dev/null
+// PR c++/67813
+// { dg-do compile { target c++14 } }
+
+struct Ptr {
+ int* p;
+
+ constexpr Ptr(int* p) noexcept : p{p} {}
+ constexpr int& operator*() const {
+ return *p;
+ }
+};
+
+constexpr int f(int& i) {
+ //Ptr first{&i}; // Works.
+ Ptr first = &i; // Error
+ return *first;
+}
+
+constexpr int g() {
+ int i = 42;
+ return f(i);
+}
+
+#define SA(X) static_assert((X), #X)
+SA(g() == 42);