re PR c++/83692 (Rejects valid constexpr with unrelated code fixing problem)
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'. * g++.dg/cpp1z/constexpr-83692.C: New test. From-SVN: r257961
This commit is contained in:
parent
2d98a9c1d5
commit
118cd6baed
@ -1,3 +1,13 @@
|
||||
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.
|
||||
|
@ -5123,8 +5123,8 @@ fold_non_dependent_expr (tree t)
|
||||
/* 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;
|
||||
@ -5139,10 +5139,10 @@ maybe_constant_init (tree t, tree decl)
|
||||
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);
|
||||
@ -5152,6 +5152,22 @@ maybe_constant_init (tree t, tree decl)
|
||||
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
|
||||
|
@ -7411,6 +7411,7 @@ extern bool require_potential_constant_expression (tree);
|
||||
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);
|
||||
|
@ -830,9 +830,10 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
|
||||
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. */
|
||||
|
@ -1,3 +1,8 @@
|
||||
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
|
||||
|
21
gcc/testsuite/g++.dg/cpp1z/constexpr-83692.C
Normal file
21
gcc/testsuite/g++.dg/cpp1z/constexpr-83692.C
Normal file
@ -0,0 +1,21 @@
|
||||
// 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{};
|
Loading…
Reference in New Issue
Block a user