Commit e1bea341 by Jason Merrill Committed by Jason Merrill

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
parent 4d612bfd
2017-10-10 Jason Merrill <jason@redhat.com> 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 * typeck.c (check_return_expr): Check non-dependent conversion in
templates. templates.
* constraint.cc (check_function_concept): Don't complain about an * constraint.cc (check_function_concept): Don't complain about an
......
...@@ -196,7 +196,14 @@ is_valid_constexpr_fn (tree fun, bool complain) ...@@ -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)); tree rettype = TREE_TYPE (TREE_TYPE (fun));
if (!literal_type_p (rettype)) if (!literal_type_p (rettype))
......
...@@ -23224,15 +23224,9 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) ...@@ -23224,15 +23224,9 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
synthesize_method (d); synthesize_method (d);
else if (TREE_CODE (d) == FUNCTION_DECL) 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. */ /* 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. */ /* Set up context. */
if (DECL_OMP_DECLARE_REDUCTION_P (code_pattern) 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) ...@@ -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; = 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. */ /* Finish the function. */
if (DECL_OMP_DECLARE_REDUCTION_P (code_pattern) if (DECL_OMP_DECLARE_REDUCTION_P (code_pattern)
&& TREE_CODE (DECL_CONTEXT (code_pattern)) == FUNCTION_DECL) && TREE_CODE (DECL_CONTEXT (code_pattern)) == FUNCTION_DECL)
...@@ -24307,21 +24297,22 @@ type_dependent_expression_p (tree expression) ...@@ -24307,21 +24297,22 @@ type_dependent_expression_p (tree expression)
&& (any_dependent_template_arguments_p && (any_dependent_template_arguments_p
(INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (expression))))) (INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (expression)))))
return true; return true;
}
/* Otherwise, if the decl isn't from a dependent scope, it can't be /* 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 type-dependent. Checking this is important for functions with auto return
return type, which looks like a dependent type. */ type, which looks like a dependent type. */
if (TREE_CODE (expression) == FUNCTION_DECL if (TREE_CODE (expression) == FUNCTION_DECL
&& (!DECL_CLASS_SCOPE_P (expression) && !(DECL_CLASS_SCOPE_P (expression)
|| !dependent_type_p (DECL_CONTEXT (expression))) && dependent_type_p (DECL_CONTEXT (expression)))
&& (!DECL_FRIEND_CONTEXT (expression) && !(DECL_FRIEND_P (expression)
|| !dependent_type_p (DECL_FRIEND_CONTEXT (expression))) && (!DECL_FRIEND_CONTEXT (expression)
&& !DECL_LOCAL_FUNCTION_P (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)); gcc_assert (!dependent_type_p (TREE_TYPE (expression))
return false; || undeduced_auto_decl (expression));
} return false;
} }
/* Always dependent, on the number of arguments if nothing else. */ /* Always dependent, on the number of arguments if nothing else. */
......
...@@ -3265,6 +3265,8 @@ outer_var_p (tree decl) ...@@ -3265,6 +3265,8 @@ outer_var_p (tree decl)
{ {
return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL) return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
&& DECL_FUNCTION_SCOPE_P (decl) && DECL_FUNCTION_SCOPE_P (decl)
/* Don't get confused by temporaries. */
&& DECL_NAME (decl)
&& (DECL_CONTEXT (decl) != current_function_decl && (DECL_CONTEXT (decl) != current_function_decl
|| parsing_nsdmi ())); || parsing_nsdmi ()));
} }
...@@ -6213,8 +6215,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) ...@@ -6213,8 +6215,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
"positive"); "positive");
t = integer_one_node; 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; OMP_CLAUSE_OPERAND (c, 1) = t;
} }
...@@ -7095,8 +7097,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) ...@@ -7095,8 +7097,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
"integral constant"); "integral constant");
remove = true; 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. */ /* Update list item. */
......
...@@ -5603,8 +5603,9 @@ tree ...@@ -5603,8 +5603,9 @@ tree
condition_conversion (tree expr) condition_conversion (tree expr)
{ {
tree t; tree t;
if (processing_template_decl) /* Anything that might happen in a template should go through
return expr; maybe_convert_cond. */
gcc_assert (!processing_template_decl);
t = perform_implicit_conversion_flags (boolean_type_node, expr, t = perform_implicit_conversion_flags (boolean_type_node, expr,
tf_warning_or_error, LOOKUP_NORMAL); tf_warning_or_error, LOOKUP_NORMAL);
t = fold_build_cleanup_point_expr (boolean_type_node, t); t = fold_build_cleanup_point_expr (boolean_type_node, t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment