diff options
author | Jason Merrill <jason@redhat.com> | 2012-03-24 16:56:08 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2012-03-24 16:56:08 -0400 |
commit | 852497a31e9bc5d98c1ada24d38d7ec7ab93f8a9 (patch) | |
tree | f4083b8417d9f0e518dd8e9e301138cb94c4b2a5 /gcc/cp/parser.c | |
parent | 8c5f2327427996b4b25ad6a4e0ce69832d025ea2 (diff) | |
download | gcc-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/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 75b7bdb..eac60f1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8416,9 +8416,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) if (LAMBDA_EXPR_RETURN_TYPE (lambda_expr)) return_type_specs.type = LAMBDA_EXPR_RETURN_TYPE (lambda_expr); else - /* Maybe we will deduce the return type later, but we can use void - as a placeholder return type anyways. */ - return_type_specs.type = void_type_node; + /* Maybe we will deduce the return type later. */ + return_type_specs.type = make_auto (); p = obstack_alloc (&declarator_obstack, 0); @@ -8539,7 +8538,8 @@ cp_parser_lambda_body (cp_parser* parser, tree lambda_expr) if (cp_parser_parse_definitely (parser)) { - apply_lambda_return_type (lambda_expr, lambda_return_type (expr)); + if (!processing_template_decl) + apply_deduced_return_type (fco, lambda_return_type (expr)); /* Will get error here if type not deduced yet. */ finish_return_stmt (expr); @@ -8550,13 +8550,10 @@ cp_parser_lambda_body (cp_parser* parser, tree lambda_expr) if (!done) { - if (!LAMBDA_EXPR_RETURN_TYPE (lambda_expr)) - LAMBDA_EXPR_DEDUCE_RETURN_TYPE_P (lambda_expr) = true; while (cp_lexer_next_token_is_keyword (parser->lexer, RID_LABEL)) cp_parser_label_declaration (parser); cp_parser_statement_seq_opt (parser, NULL_TREE); cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); - LAMBDA_EXPR_DEDUCE_RETURN_TYPE_P (lambda_expr) = false; } finish_compound_stmt (compound_stmt); @@ -11275,8 +11272,14 @@ cp_parser_conversion_type_id (cp_parser* parser) if (! cp_parser_uncommitted_to_tentative_parse_p (parser) && type_uses_auto (type_specified)) { - error ("invalid use of %<auto%> in conversion operator"); - return error_mark_node; + if (cxx_dialect < cxx1y) + { + error ("invalid use of %<auto%> in conversion operator"); + return error_mark_node; + } + else if (template_parm_scope_p ()) + warning (0, "use of %<auto%> in member template " + "conversion operator can never be deduced"); } return type_specified; |