aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/semantics.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2012-03-24 16:56:08 -0400
committerJason Merrill <jason@gcc.gnu.org>2012-03-24 16:56:08 -0400
commit852497a31e9bc5d98c1ada24d38d7ec7ab93f8a9 (patch)
treef4083b8417d9f0e518dd8e9e301138cb94c4b2a5 /gcc/cp/semantics.c
parent8c5f2327427996b4b25ad6a4e0ce69832d025ea2 (diff)
downloadgcc-852497a31e9bc5d98c1ada24d38d7ec7ab93f8a9.zip
gcc-852497a31e9bc5d98c1ada24d38d7ec7ab93f8a9.tar.gz
gcc-852497a31e9bc5d98c1ada24d38d7ec7ab93f8a9.tar.bz2
Implement return type deduction for normal functions with -std=c++1y.
* cp-tree.h (FNDECL_USED_AUTO): New macro. (LAMBDA_EXPR_DEDUCE_RETURN_TYPE_P): Remove. (dependent_lambda_return_type_node): Remove. (CPTI_DEPENDENT_LAMBDA_RETURN_TYPE): Remove. (struct language_function): Add x_auto_return_pattern field. (current_function_auto_return_pattern): New. (enum tsubst_flags): Add tf_partial. * decl.c (decls_match): Handle auto return comparison. (duplicate_decls): Adjust error message for auto return. (cxx_init_decl_processing): Remove dependent_lambda_return_type_node. (cp_finish_decl): Don't do auto deduction for functions. (grokdeclarator): Allow auto return without trailing return type in C++1y mode. (check_function_type): Defer checking of deduced return type. (start_preparsed_function): Set current_function_auto_return_pattern. (finish_function): Set deduced return type to void if not previously deduced. * decl2.c (change_return_type): Handle error_mark_node. (mark_used): Always instantiate functions with deduced return type. Complain about use if deduction isn't done. * parser.c (cp_parser_lambda_declarator_opt): Use 'auto' for initial return type. (cp_parser_lambda_body): Don't deduce return type in a template. (cp_parser_conversion_type_id): Allow auto in C++1y. * pt.c (instantiate_class_template_1): Don't mess with LAMBDA_EXPR_DEDUCE_RETURN_TYPE_P. (tsubst_copy_and_build): Likewise. (fn_type_unification, tsubst): Don't reduce the template parm level of 'auto' during deduction. (unify): Compare 'auto' specially. (get_bindings): Change test. (always_instantiate_p): Always instantiate functions with deduced return type. (do_auto_deduction): Handle error_mark_node and lambda context. Don't check for use in initializer. (contains_auto_r): Remove. * search.c (lookup_conversions_r): Handle auto conversion function. * semantics.c (lambda_return_type): Handle null return. Don't mess with dependent_lambda_return_type_node. (apply_deduced_return_type): Rename from apply_lambda_return_type. * typeck.c (merge_types): Handle auto. (check_return_expr): Do auto deduction. * typeck2.c (add_exception_specifier): Fix complain check. From-SVN: r185768
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r--gcc/cp/semantics.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 5646fa7..6294e19 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8691,18 +8691,16 @@ begin_lambda_type (tree lambda)
tree
lambda_return_type (tree expr)
{
- tree type;
+ if (expr == NULL_TREE)
+ return void_type_node;
if (type_unknown_p (expr)
|| BRACE_ENCLOSED_INITIALIZER_P (expr))
{
cxx_incomplete_type_error (expr, TREE_TYPE (expr));
return void_type_node;
}
- if (type_dependent_expression_p (expr))
- type = dependent_lambda_return_type_node;
- else
- type = cv_unqualified (type_decays_to (unlowered_expr_type (expr)));
- return type;
+ gcc_checking_assert (!type_dependent_expression_p (expr));
+ return cv_unqualified (type_decays_to (unlowered_expr_type (expr)));
}
/* Given a LAMBDA_EXPR or closure type LAMBDA, return the op() of the
@@ -8749,29 +8747,32 @@ lambda_capture_field_type (tree expr)
return type;
}
-/* Recompute the return type for LAMBDA with body of the form:
- { return EXPR ; } */
+/* Insert the deduced return type for an auto function. */
void
-apply_lambda_return_type (tree lambda, tree return_type)
+apply_deduced_return_type (tree fco, tree return_type)
{
- tree fco = lambda_function (lambda);
tree result;
- LAMBDA_EXPR_RETURN_TYPE (lambda) = return_type;
-
if (return_type == error_mark_node)
return;
- if (TREE_TYPE (TREE_TYPE (fco)) == return_type)
- return;
- /* TREE_TYPE (FUNCTION_DECL) == METHOD_TYPE
- TREE_TYPE (METHOD_TYPE) == return-type */
+ if (LAMBDA_FUNCTION_P (fco))
+ {
+ tree lambda = CLASSTYPE_LAMBDA_EXPR (current_class_type);
+ LAMBDA_EXPR_RETURN_TYPE (lambda) = return_type;
+ }
+
+ if (DECL_CONV_FN_P (fco))
+ DECL_NAME (fco) = mangle_conv_op_name_for_type (return_type);
+
TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
result = DECL_RESULT (fco);
if (result == NULL_TREE)
return;
+ if (TREE_TYPE (result) == return_type)
+ return;
/* We already have a DECL_RESULT from start_preparsed_function.
Now we need to redo the work it and allocate_struct_function
@@ -8786,12 +8787,13 @@ apply_lambda_return_type (tree lambda, tree return_type)
DECL_RESULT (fco) = result;
- if (!processing_template_decl && aggregate_value_p (result, fco))
+ if (!processing_template_decl)
{
+ bool aggr = aggregate_value_p (result, fco);
#ifdef PCC_STATIC_STRUCT_RETURN
- cfun->returns_pcc_struct = 1;
+ cfun->returns_pcc_struct = aggr;
#endif
- cfun->returns_struct = 1;
+ cfun->returns_struct = aggr;
}
}