@@ -937,6 +937,31 @@ initializer lists can have their braces ignored.
937937} /* ignore_braces_for_placeholder_deduction */
938938
939939
940+ static an_error_code error_for_failed_auto_deduction(
941+ a_boolean is_decltype_auto,
942+ a_type_ptr initializer_type)
943+ /*
944+ Return the diagnostic for a failed placeholder-type deduction.
945+ is_decltype_auto is TRUE when the placeholder is decltype(auto).
946+ initializer_type is the type of the initializer, or NULL when that type is
947+ not available (for example, a braced-init-list).
948+ */
949+ {
950+ an_error_code result;
951+
952+ if (is_decltype_auto) {
953+ result = ec_cannot_deduce_decltype_auto_type;
954+ } else if (initializer_type != NULL && is_void_type(initializer_type)) {
955+ /* void is not an object type, so deduction cannot succeed. Name that
956+ type instead of using the generic message. */
957+ result = ec_cannot_deduce_auto_from_void;
958+ } else {
959+ result = ec_cannot_deduce_auto_type;
960+ } /* if */
961+ return result;
962+ } /* error_for_failed_auto_deduction */
963+
964+
940965void prescan_initializer_for_auto_type_deduction(
941966 a_decl_parse_state *dps,
942967 a_boolean parenthesized_init)
@@ -1178,12 +1203,20 @@ swallowed); otherwise, it's "="-form or "{...}" form.
11781203 dps->deduced_auto_type = unknown_type();
11791204 } else {
11801205 /* Deduction failed. */
1181- expr_pos_error(dps->has_deducible_class_templ_args ?
1182- ec_cannot_deduce_class_template_arguments :
1183- (an_error_code)(dps->decltype_auto_specifier_seen ?
1184- ec_cannot_deduce_decltype_auto_type :
1185- ec_cannot_deduce_auto_type),
1186- &dps->auto_pos);
1206+ { an_error_code err_code;
1207+ a_type_ptr init_type = NULL;
1208+
1209+ if (dps->has_deducible_class_templ_args) {
1210+ err_code = ec_cannot_deduce_class_template_arguments;
1211+ } else {
1212+ if (icp != NULL && is_expression_component(icp)) {
1213+ init_type = operand_of_arg_list_elem(icp)->type;
1214+ } /* if */
1215+ err_code = error_for_failed_auto_deduction(
1216+ dps->decltype_auto_specifier_seen, init_type);
1217+ } /* if */
1218+ expr_pos_error(err_code, &dps->auto_pos);
1219+ }
11871220 dps->specifiers_type = dps->deduced_auto_type = dps->type =
11881221 error_type();
11891222 dps->has_deduced_type = FALSE;
@@ -48752,9 +48785,9 @@ the type of element_operand and sets the variable type to the deduced type.
4875248785 type as it is. */
4875348786 } else {
4875448787 /* Deduction failed. */
48755- pos_error(iterator->declared_with_decltype_auto ?
48756- ec_cannot_deduce_decltype_auto_type :
48757- ec_cannot_deduce_auto_type ,
48788+ pos_error(error_for_failed_auto_deduction(
48789+ iterator->declared_with_decltype_auto,
48790+ element_operand->type) ,
4875848791 &iterator->source_corresp.decl_position);
4875948792 iterator->type = error_type();
4876048793 } /* if */
@@ -52389,7 +52422,9 @@ are left unaffected).
5238952422 is_decltype_auto_case = TRUE;
5239052423 } /* if */
5239152424 } else {
52392- pos_error(ec_cannot_deduce_auto_type, diag_pos);
52425+ /* The declared type is not a plain "auto" (for example, "auto *").
52426+ void still cannot be used to deduce it. */
52427+ pos_error(ec_cannot_deduce_auto_from_void, diag_pos);
5239352428 deduced_return_type = error_type();
5239452429 } /* if */
5239552430 if (keep_placeholder) {
@@ -52489,8 +52524,8 @@ type with the type of return_op.
5248952524 /* The type is still dependent, so leave the return type as it is. */
5249052525 } else {
5249152526 /* Deduction failed. */
52492- pos_error(is_decltype_auto ? ec_cannot_deduce_decltype_auto_type
52493- : ec_cannot_deduce_auto_type ,
52527+ pos_error(error_for_failed_auto_deduction( is_decltype_auto,
52528+ return_op->type) ,
5249452529 &return_op->position);
5249552530 *return_type = error_type();
5249652531 rout_type->variant.routine.return_type = *return_type;
0 commit comments