diff options
author | Jason Merrill <jason@redhat.com> | 2016-04-13 11:02:17 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2016-04-13 11:02:17 -0400 |
commit | eb07f187a471f9a203626aecced17d6947c3cc46 (patch) | |
tree | 4df20658e32c740c4941fef058a9e3b8e224f226 | |
parent | 3eddc1c9718c6b8264d42cda6e76a3dd9ffc93f0 (diff) | |
download | gcc-eb07f187a471f9a203626aecced17d6947c3cc46.zip gcc-eb07f187a471f9a203626aecced17d6947c3cc46.tar.gz gcc-eb07f187a471f9a203626aecced17d6947c3cc46.tar.bz2 |
constexpr.c (potential_nondependent_constant_expression): New.
* 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
-rw-r--r-- | gcc/cp/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 38 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 2 | ||||
-rw-r--r-- | gcc/cp/pt.c | 12 |
4 files changed, 45 insertions, 18 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4412994..6942c8d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +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 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 13f385b..37cc336 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4315,10 +4315,7 @@ maybe_constant_value_1 (tree t, tree decl) { 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)) { @@ -4397,8 +4394,7 @@ fold_non_dependent_expr (tree 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); @@ -4449,10 +4445,7 @@ maybe_constant_init (tree t, tree decl) 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); @@ -5203,4 +5196,29 @@ require_potential_rvalue_constant_expression (tree t) 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" diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 0f7e08f..ecf2a5d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6884,6 +6884,8 @@ extern tree register_constexpr_fundef (tree, tree); 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); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2d93a5c..2871f33 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5655,8 +5655,7 @@ instantiate_non_dependent_expr_sfinae (tree expr, tsubst_flags_t complain) 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); @@ -5680,8 +5679,7 @@ instantiate_non_dependent_or_null (tree expr) 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 { @@ -6240,10 +6238,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) 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; |