2014-11-17 Jason Merrill <jason@redhat.com>
+ PR c++/50473
+ * decl.c (cp_finish_decl): Don't try to process a non-dependent
+ constant initializer for a reference.
+ * pt.c (value_dependent_expression_p): A reference is always
+ dependent.
+ * call.c (extend_ref_init_temps_1): Also clear TREE_SIDE_EFFECTS
+ on any NOP_EXPRs.
+
Handle C++14 constexpr flow control.
* constexpr.c (cxx_eval_loop_expr, cxx_eval_switch_expr): New.
(cxx_eval_statement_list): New.
{
tree subinit = NULL_TREE;
*p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit);
+ recompute_tree_invariant_for_addr_expr (sub);
+ if (init != sub)
+ init = fold_convert (TREE_TYPE (init), sub);
if (subinit)
init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
- recompute_tree_invariant_for_addr_expr (sub);
}
return init;
}
else if (init
&& init_const_expr_p
&& !type_dependent_p
+ && TREE_CODE (type) != REFERENCE_TYPE
&& decl_maybe_constant_var_p (decl)
&& !type_dependent_init_p (init)
&& !value_dependent_init_p (init))
if (DECL_INITIAL (expression)
&& decl_constant_var_p (expression)
&& (TREE_CODE (DECL_INITIAL (expression)) == TREE_LIST
+ /* cp_finish_decl doesn't fold reference initializers. */
+ || TREE_CODE (TREE_TYPE (expression)) == REFERENCE_TYPE
|| value_dependent_expression_p (DECL_INITIAL (expression))))
return true;
return false;
struct A
{
- static constexpr int&& i = 0; // { dg-error "initialization" }
+ static constexpr int&& i = 0;
};
int j = A::i;
--- /dev/null
+// PR c++/50473
+// { dg-do compile { target c++11 } }
+
+constexpr int f() { return 1; }
+
+template<class T>
+struct test
+{
+ static constexpr const auto& value = f();
+ int a[value];
+};
+
+test<int> t;