From e1bea3412a75a300c3866dcf9559c2b796f5b430 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 10 Oct 2017 14:03:56 -0400 Subject: [PATCH] Various small C++ fixes. * 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 | 9 +++++++++ gcc/cp/constexpr.c | 9 ++++++++- gcc/cp/pt.c | 43 +++++++++++++++++-------------------------- gcc/cp/semantics.c | 6 ++++-- gcc/cp/typeck.c | 5 +++-- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fe0315c88e0..50df3cbe56c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,14 @@ 2017-10-10 Jason Merrill + * 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 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 8a5be2079d8..f279f707676 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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)) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 52fc4d6a222..d93d518c22d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 *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; + 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. */ diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 77c71e71bcf..5bc74820a90 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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. */ diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 01647d04bc8..90a1f47e3fd 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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); -- 2.30.2