tree auto_node = type_uses_auto (type);
if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
{
+ bool err_p = true;
if (cxx_dialect >= cxx14)
{
if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
"abbreviated function template");
inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
}
- else
+ else if (decl_context == CATCHPARM || template_parm_flag)
error_at (typespec_loc,
"%<auto%> parameter not permitted in this context");
+ else
+ /* Do not issue an error while tentatively parsing a function
+ parameter: for T t(auto(a), 42);, when we just saw the 1st
+ parameter, we don't know yet that this construct won't be
+ a function declaration. Defer the checking to
+ cp_parser_parameter_declaration_clause. */
+ err_p = false;
}
else
error_at (typespec_loc, "parameter declared %<auto%>");
- type = error_mark_node;
+ if (err_p)
+ type = error_mark_node;
}
/* A parameter declared as an array of T is really a pointer to T.
committed yet, nor should we. Pushing here will detect the error
of redefining a parameter. */
if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))
- for (tree p : pending_decls)
- pushdecl (p);
+ {
+ for (tree p : pending_decls)
+ pushdecl (p);
+
+ /* Delayed checking of auto parameters. */
+ if (!parser->auto_is_implicit_function_template_parm_p
+ && cxx_dialect >= cxx14)
+ for (tree p = parameters; p; p = TREE_CHAIN (p))
+ if (type_uses_auto (TREE_TYPE (TREE_VALUE (p))))
+ {
+ error_at (location_of (TREE_VALUE (p)),
+ "%<auto%> parameter not permitted in this context");
+ TREE_TYPE (TREE_VALUE (p)) = error_mark_node;
+ }
+ }
/* Finish the parameter list. */
if (!ellipsis_p)
--- /dev/null
+// PR c++/112482
+// { dg-do compile { target c++23 } }
+// { dg-options "-Wno-vexing-parse" }
+
+void foo (auto i, auto j);
+
+struct A {
+ A(int,int);
+};
+
+void
+g (int a)
+{
+ A b1(auto(42), auto(42));
+ A b2(auto(a), auto(42));
+ A b3(auto(42), auto(a));
+ A b4(auto(a), // { dg-error "13:'auto' parameter" }
+ auto(a2)); // { dg-error "13:'auto' parameter" }
+ int v1(auto(42));
+ int fn1(auto(a)); // { dg-error "16:'auto' parameter" }
+}