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
This commit is contained in:
Jason Merrill 2017-10-10 14:03:56 -04:00 committed by Jason Merrill
parent 4d612bfde8
commit e1bea3412a
5 changed files with 41 additions and 31 deletions

View 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

View 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))

View 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. */

View 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. */

View 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);