constexpr.c (potential_nondependent_constant_expression): New.
authorJason Merrill <jason@redhat.com>
Wed, 13 Apr 2016 15:02:17 +0000 (11:02 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 13 Apr 2016 15:02:17 +0000 (11:02 -0400)
* 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

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/cp/cp-tree.h
gcc/cp/pt.c

index 4412994bd57178c22e1f953ad439fb71a78b8303..6942c8dd5d33c50fc202a4fb7de65a6a62f070dd 100644 (file)
@@ -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
index 13f385b5a19447f28872e5b7e9cf39cf2184d5d9..37cc336598306b391ce3ba3181fc2ef2bf57aa42 100644 (file)
@@ -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"
index 0f7e08ffe73c174f13d6294b8dcf26a2fb155290..ecf2a5d5a122b03af4aa72339d8155dc58df7896 100644 (file)
@@ -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);
index 2d93a5c9169e00fc5047e15a069fe1fcef23f8a6..2871f339fffead7bd68a17f9a2f9eb2cd9931539 100644 (file)
@@ -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;