* constexpr.c (potential_nondependent_constant_expression): New.
(potential_nondependent_static_init_expression): New.
(maybe_constant_value_1, fold_non_dependent_expr)
(maybe_constant_init): Use them.
* pt.c (instantiate_non_dependent_expr_sfinae)
(instantiate_non_dependent_or_null, convert_nontype_argument): Use
them.
* cp-tree.h: Declare them.
From-SVN: r234944
+2016-04-13 Jason Merrill <jason@redhat.com>
+
+ * constexpr.c (potential_nondependent_constant_expression): New.
+ (potential_nondependent_static_init_expression): New.
+ (maybe_constant_value_1, fold_non_dependent_expr)
+ (maybe_constant_init): Use them.
+ * pt.c (instantiate_non_dependent_expr_sfinae)
+ (instantiate_non_dependent_or_null, convert_nontype_argument): Use
+ them.
+ * cp-tree.h: Declare them.
+
2016-04-13 Jakub Jelinek <jakub@redhat.com>
PR c++/70594
{
tree r;
- if (instantiation_dependent_expression_p (t)
- || type_unknown_p (t)
- || BRACE_ENCLOSED_INITIALIZER_P (t)
- || !potential_constant_expression (t))
+ if (!potential_nondependent_constant_expression (t))
{
if (TREE_OVERFLOW_P (t))
{
as two declarations of the same function, for example. */
if (processing_template_decl)
{
- if (!instantiation_dependent_expression_p (t)
- && potential_constant_expression (t))
+ if (potential_nondependent_constant_expression (t))
{
processing_template_decl_sentinel s;
t = instantiate_non_dependent_expr_internal (t, tf_none);
t = TREE_OPERAND (t, 0);
if (TREE_CODE (t) == INIT_EXPR)
t = TREE_OPERAND (t, 1);
- if (instantiation_dependent_expression_p (t)
- || type_unknown_p (t)
- || BRACE_ENCLOSED_INITIALIZER_P (t)
- || !potential_static_init_expression (t))
+ if (!potential_nondependent_static_init_expression (t))
/* Don't try to evaluate it. */;
else
t = cxx_eval_outermost_constant_expr (t, true, false, decl);
return potential_constant_expression_1 (t, true, true, tf_warning_or_error);
}
+/* Returns true if T is a potential constant expression that is not
+ instantiation-dependent, and therefore a candidate for constant folding even
+ in a template. */
+
+bool
+potential_nondependent_constant_expression (tree t)
+{
+ return (!type_unknown_p (t)
+ && !BRACE_ENCLOSED_INITIALIZER_P (t)
+ && potential_constant_expression (t)
+ && !instantiation_dependent_expression_p (t));
+}
+
+/* Returns true if T is a potential static initializer expression that is not
+ instantiation-dependent. */
+
+bool
+potential_nondependent_static_init_expression (tree t)
+{
+ return (!type_unknown_p (t)
+ && !BRACE_ENCLOSED_INITIALIZER_P (t)
+ && potential_static_init_expression (t)
+ && !instantiation_dependent_expression_p (t));
+}
+
#include "gt-cp-constexpr.h"
extern bool check_constexpr_ctor_body (tree, tree, bool);
extern tree ensure_literal_type_for_constexpr_object (tree);
extern bool potential_constant_expression (tree);
+extern bool potential_nondependent_constant_expression (tree);
+extern bool potential_nondependent_static_init_expression (tree);
extern bool potential_static_init_expression (tree);
extern bool potential_rvalue_constant_expression (tree);
extern bool require_potential_constant_expression (tree);
as two declarations of the same function, for example. */
if (processing_template_decl
- && !instantiation_dependent_expression_p (expr)
- && potential_constant_expression (expr))
+ && potential_nondependent_constant_expression (expr))
{
processing_template_decl_sentinel s;
expr = instantiate_non_dependent_expr_internal (expr, complain);
return NULL_TREE;
if (processing_template_decl)
{
- if (instantiation_dependent_expression_p (expr)
- || !potential_constant_expression (expr))
+ if (!potential_nondependent_constant_expression (expr))
expr = NULL_TREE;
else
{
if (TYPE_REF_OBJ_P (type)
&& has_value_dependent_address (expr))
/* If we want the address and it's value-dependent, don't fold. */;
- else if (!type_unknown_p (expr)
- && processing_template_decl
- && !instantiation_dependent_expression_p (expr)
- && potential_constant_expression (expr))
+ else if (processing_template_decl
+ && potential_nondependent_constant_expression (expr))
non_dep = true;
if (error_operand_p (expr))
return error_mark_node;