summaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorabutcher <abutcher@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-16 07:14:34 +0000
committerabutcher <abutcher@138bc75d-0d04-0410-961f-82ee72b054a4>2013-09-16 07:14:34 +0000
commit46b2b0ac933fb82a5a3228dc58f013246e36fbac (patch)
tree7b1d4ac4d3e611d0294babd60fb9894821a0f303 /gcc/cp/decl.c
parent814b90efc51ecb609d1ab98d96472797e77937b0 (diff)
downloadgcc-46b2b0ac933fb82a5a3228dc58f013246e36fbac.tar.gz
Support using 'auto' in a function parameter list to introduce an implicit template parameter.
gcc/cp/ * cp-tree.h (type_uses_auto_or_concept): Declare. (is_auto_or_concept): Declare. * decl.c (grokdeclarator): Allow 'auto' parameters in lambdas with -std=gnu++1y or -std=c++1y or, as a GNU extension, in plain functions. * type-utils.h: New header defining ... (find_type_usage): ... this new function based on pt.c (type_uses_auto) for searching a type tree given a predicate. * pt.c (type_uses_auto): Reimplement via type-utils.h (find_type_usage). (is_auto_or_concept): New function. (type_uses_auto_or_concept): New function. * parser.h (struct cp_parser): Add fully_implicit_function_template_p. * parser.c (cp_parser_new): Initialize fully_implicit_function_template_p. (cp_parser_new): Initialize fully_implicit_function_template_p. (cp_parser_lambda_expression): Copy and restore value of fully_implicit_function_template_p as per other parser fields. (cp_parser_parameter_declaration_list): Count generic parameters and call ... (add_implicit_template_parms): ... this new function to synthesize them with help from type-utils.h (find_type_usage), ... (tree_type_is_auto_or_concept): ... this new static function and ... (make_generic_type_name): ... this new static function. (cp_parser_direct_declarator): Account for implicit template parameters. (cp_parser_lambda_declarator_opt): Finish fully implicit template if necessary by calling ... (finish_fully_implicit_template): ... this new function. (cp_parser_init_declarator): Likewise. (cp_parser_function_definition_after_declarator): Likewise. (cp_parser_member_declaration): Likewise. * Make-lang.in (cp/pt.o): Add dependency on type-utils.h. (cp/parser.o): Likewise. gcc/testsuite/ g++.dg/cpp0x/auto9.C: Downgrade two previously expected errors (now interpreted as implicit templates) to be expected pedwarns instead. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202612 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index f193676c382..80ceca138d8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10323,8 +10323,33 @@ grokdeclarator (const cp_declarator *declarator,
if (type_uses_auto (type))
{
- error ("parameter declared %<auto%>");
- type = error_mark_node;
+ if (template_parm_flag)
+ {
+ error ("template parameter declared %<auto%>");
+ type = error_mark_node;
+ }
+ else if (decl_context == CATCHPARM)
+ {
+ error ("catch parameter declared %<auto%>");
+ type = error_mark_node;
+ }
+ else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
+ {
+ if (cxx_dialect < cxx1y)
+ pedwarn (location_of (type), 0,
+ "use of %<auto%> in lambda parameter declaration "
+ "only available with "
+ "-std=c++1y or -std=gnu++1y");
+ }
+ else if (cxx_dialect < cxx1y)
+ pedwarn (location_of (type), 0,
+ "use of %<auto%> in parameter declaration "
+ "only available with "
+ "-std=c++1y or -std=gnu++1y");
+ else
+ pedwarn (location_of (type), OPT_Wpedantic,
+ "ISO C++ forbids use of %<auto%> in parameter "
+ "declaration");
}
/* A parameter declared as an array of T is really a pointer to T.