+2018-02-24 Marek Polacek <polacek@redhat.com>
+
+ PR c++/83692
+ * constexpr.c (maybe_constant_init_1): New function.
+ (maybe_constant_init): Make it a wrapper around maybe_constant_init_1.
+ (cxx_constant_init): New function.
+ * cp-tree.h (cxx_constant_init): Declare.
+ * typeck2.c (store_init_value): Call cxx_constant_init instead of
+ cxx_constant_value. Move the maybe_constant_init call under an 'else'.
+
2018-02-22 Jason Merrill <jason@redhat.com>
PR c++/70468 - ICE with constructor delegation via typedef.
/* Like maybe_constant_value, but returns a CONSTRUCTOR directly, rather
than wrapped in a TARGET_EXPR. */
-tree
-maybe_constant_init (tree t, tree decl)
+static tree
+maybe_constant_init_1 (tree t, tree decl, bool allow_non_constant)
{
if (!t)
return t;
t = TARGET_EXPR_INITIAL (t);
if (!is_nondependent_static_init_expression (t))
/* Don't try to evaluate it. */;
- else if (CONSTANT_CLASS_P (t))
+ else if (CONSTANT_CLASS_P (t) && allow_non_constant)
/* No evaluation needed. */;
else
- t = cxx_eval_outermost_constant_expr (t, true, false, decl);
+ t = cxx_eval_outermost_constant_expr (t, allow_non_constant, false, decl);
if (TREE_CODE (t) == TARGET_EXPR)
{
tree init = TARGET_EXPR_INITIAL (t);
return t;
}
+/* Wrapper for maybe_constant_init_1 which permits non constants. */
+
+tree
+maybe_constant_init (tree t, tree decl)
+{
+ return maybe_constant_init_1 (t, decl, true);
+}
+
+/* Wrapper for maybe_constant_init_1 which does not permit non constants. */
+
+tree
+cxx_constant_init (tree t, tree decl)
+{
+ return maybe_constant_init_1 (t, decl, false);
+}
+
#if 0
/* FIXME see ADDR_EXPR section in potential_constant_expression_1. */
/* Return true if the object referred to by REF has automatic or thread
extern bool require_constant_expression (tree);
extern bool require_potential_rvalue_constant_expression (tree);
extern tree cxx_constant_value (tree, tree = NULL_TREE);
+extern tree cxx_constant_init (tree, tree = NULL_TREE);
extern tree maybe_constant_value (tree, tree = NULL_TREE);
extern tree maybe_constant_init (tree, tree = NULL_TREE);
extern tree fold_non_dependent_expr (tree);
if (!require_constant_expression (value))
value = error_mark_node;
else
- value = cxx_constant_value (value, decl);
+ value = cxx_constant_init (value, decl);
}
- value = maybe_constant_init (value, decl);
+ else
+ value = maybe_constant_init (value, decl);
if (TREE_CODE (value) == CONSTRUCTOR && cp_has_mutable_p (type))
/* Poison this CONSTRUCTOR so it can't be copied to another
constexpr variable. */
+2018-02-24 Marek Polacek <polacek@redhat.com>
+
+ PR c++/83692
+ * g++.dg/cpp1z/constexpr-83692.C: New test.
+
2018-02-23 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/84346
--- /dev/null
+// PR c++/83692
+// { dg-options -std=c++17 }
+
+struct integer {
+ constexpr int value() const { return m_value; }
+ int m_value;
+};
+
+struct outer {
+ integer m_x{0};
+ constexpr outer()
+ {
+ if (m_x.value() != 0)
+ throw 0;
+ m_x.m_value = integer{1}.value();
+ if (m_x.value() != 1)
+ throw 0;
+ }
+};
+
+constexpr outer o{};