Various small C++ fixes.
authorJason Merrill <jason@redhat.com>
Tue, 10 Oct 2017 18:03:56 +0000 (14:03 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 10 Oct 2017 18:03:56 +0000 (14:03 -0400)
* typeck.c (condition_conversion): Assert !processing_template_decl.
* semantics.c (finish_omp_clauses): Don't
fold_build_cleanup_point_expr if processing_template_decl.
(outer_var_p): A temporary can't be from an outer scope.
* pt.c (type_dependent_expression_p): Fix dependency checking of
functions without DECL_TEMPLATE_INFO.
(instantiate_decl): Use lss_copy.
* constexpr.c (is_valid_constexpr_fn): Fix lambdas before C++17.

From-SVN: r253600

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/cp/typeck.c

index fe0315c88e0dc6fc88c10a9d8af38bc76b9d6adc..50df3cbe56c2b11c4f4a0fc7f1cdce892f94fe4e 100644 (file)
@@ -1,5 +1,14 @@
 2017-10-10  Jason Merrill  <jason@redhat.com>
 
+       * typeck.c (condition_conversion): Assert !processing_template_decl.
+       * semantics.c (finish_omp_clauses): Don't
+       fold_build_cleanup_point_expr if processing_template_decl.
+       (outer_var_p): A temporary can't be from an outer scope.
+       * pt.c (type_dependent_expression_p): Fix dependency checking of
+       functions without DECL_TEMPLATE_INFO.
+       (instantiate_decl): Use lss_copy.
+       * constexpr.c (is_valid_constexpr_fn): Fix lambdas before C++17.
+
        * typeck.c (check_return_expr): Check non-dependent conversion in
        templates.
        * constraint.cc (check_function_concept): Don't complain about an
index 8a5be2079d8dfdf0e744df65238aec8401696161..f279f707676c2f3411d758082d7db58e3b7bc67e 100644 (file)
@@ -196,7 +196,14 @@ is_valid_constexpr_fn (tree fun, bool complain)
          }
     }
 
-  if (!DECL_CONSTRUCTOR_P (fun))
+  if (LAMBDA_TYPE_P (CP_DECL_CONTEXT (fun)) && cxx_dialect < cxx17)
+    {
+      ret = false;
+      if (complain)
+       inform (DECL_SOURCE_LOCATION (fun),
+               "lambdas are implicitly constexpr only in C++17 and later");
+    }
+  else if (!DECL_CONSTRUCTOR_P (fun))
     {
       tree rettype = TREE_TYPE (TREE_TYPE (fun));
       if (!literal_type_p (rettype))
index 52fc4d6a222e67c9d27866561848cff7efc29a37..d93d518c22d88de1a2277af3767c5a7733375a88 100644 (file)
@@ -23224,15 +23224,9 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
     synthesize_method (d);
   else if (TREE_CODE (d) == FUNCTION_DECL)
     {
-      hash_map<tree, tree> *saved_local_specializations;
-      tree block = NULL_TREE;
-
-      /* Save away the current list, in case we are instantiating one
-        template from within the body of another.  */
-      saved_local_specializations = local_specializations;
-
       /* Set up the list of local specializations.  */
-      local_specializations = new hash_map<tree, tree>;
+      local_specialization_stack lss (push_to_top ? lss_blank : lss_copy);
+      tree block = NULL_TREE;
 
       /* Set up context.  */
       if (DECL_OMP_DECLARE_REDUCTION_P (code_pattern)
@@ -23271,10 +23265,6 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
            = DECL_STRUCT_FUNCTION (code_pattern)->language->infinite_loop;
        }
 
-      /* We don't need the local specializations any more.  */
-      delete local_specializations;
-      local_specializations = saved_local_specializations;
-
       /* Finish the function.  */
       if (DECL_OMP_DECLARE_REDUCTION_P (code_pattern)
          && TREE_CODE (DECL_CONTEXT (code_pattern)) == FUNCTION_DECL)
@@ -24307,21 +24297,22 @@ type_dependent_expression_p (tree expression)
          && (any_dependent_template_arguments_p
              (INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (expression)))))
        return true;
+    }
 
-      /* Otherwise, if the decl isn't from a dependent scope, it can't be
-        type-dependent.  Checking this is important for functions with auto
-        return type, which looks like a dependent type.  */
-      if (TREE_CODE (expression) == FUNCTION_DECL
-         && (!DECL_CLASS_SCOPE_P (expression)
-             || !dependent_type_p (DECL_CONTEXT (expression)))
-         && (!DECL_FRIEND_CONTEXT (expression)
-             || !dependent_type_p (DECL_FRIEND_CONTEXT (expression)))
-         && !DECL_LOCAL_FUNCTION_P (expression))
-       {
-         gcc_assert (!dependent_type_p (TREE_TYPE (expression))
-                     || undeduced_auto_decl (expression));
-         return false;
-       }
+  /* Otherwise, if the function decl isn't from a dependent scope, it can't be
+     type-dependent.  Checking this is important for functions with auto return
+     type, which looks like a dependent type.  */
+  if (TREE_CODE (expression) == FUNCTION_DECL
+      && !(DECL_CLASS_SCOPE_P (expression)
+          && dependent_type_p (DECL_CONTEXT (expression)))
+      && !(DECL_FRIEND_P (expression)
+          && (!DECL_FRIEND_CONTEXT (expression)
+              || dependent_type_p (DECL_FRIEND_CONTEXT (expression))))
+      && !DECL_LOCAL_FUNCTION_P (expression))
+    {
+      gcc_assert (!dependent_type_p (TREE_TYPE (expression))
+                 || undeduced_auto_decl (expression));
+      return false;
     }
 
   /* Always dependent, on the number of arguments if nothing else.  */
index 77c71e71bcf4c4efb2f83dc1387c47e078c43229..5bc74820a903b947cadc7669e82d86c86aab84cc 100644 (file)
@@ -3265,6 +3265,8 @@ outer_var_p (tree decl)
 {
   return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
          && DECL_FUNCTION_SCOPE_P (decl)
+         /* Don't get confused by temporaries.  */
+         && DECL_NAME (decl)
          && (DECL_CONTEXT (decl) != current_function_decl
              || parsing_nsdmi ()));
 }
@@ -6213,8 +6215,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
                                      "positive");
                          t = integer_one_node;
                        }
+                     t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
                    }
-                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
                }
              OMP_CLAUSE_OPERAND (c, 1) = t;
            }
@@ -7095,8 +7097,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
                                    "integral constant");
                          remove = true;
                        }
+                     t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
                    }
-                 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
                }
 
                /* Update list item.  */
index 01647d04bc8b8ce3f6e9cc7631767f350f9c731e..90a1f47e3fd57affd9da7717ce73a212b8b89c32 100644 (file)
@@ -5603,8 +5603,9 @@ tree
 condition_conversion (tree expr)
 {
   tree t;
-  if (processing_template_decl)
-    return expr;
+  /* Anything that might happen in a template should go through
+     maybe_convert_cond.  */
+  gcc_assert (!processing_template_decl);
   t = perform_implicit_conversion_flags (boolean_type_node, expr,
                                         tf_warning_or_error, LOOKUP_NORMAL);
   t = fold_build_cleanup_point_expr (boolean_type_node, t);