static tree cp_parser_init_declarator
(cp_parser *, cp_decl_specifier_seq *, vec<deferred_access_check, va_gc> *,
- bool, bool, int, bool *, tree *, location_t *);
+ bool, bool, int, bool *, tree *, location_t *, tree *);
static cp_declarator *cp_parser_declarator
(cp_parser *, cp_parser_declarator_kind, int *, bool *, bool, bool);
static cp_declarator *cp_parser_direct_declarator
&& !cp_parser_error_occurred (parser))
cp_parser_commit_to_tentative_parse (parser);
- tree last_type, auto_node;
+ tree last_type;
last_type = NULL_TREE;
- auto_node = type_uses_auto (decl_specifiers.type);
/* Keep going until we hit the `;' at the end of the simple
declaration. */
cp_token *token;
bool function_definition_p;
tree decl;
+ tree auto_result = NULL_TREE;
if (saw_declarator)
{
declares_class_or_enum,
&function_definition_p,
maybe_range_for_decl,
- &init_loc);
+ &init_loc,
+ &auto_result);
/* If an error occurred while parsing tentatively, exit quickly.
(That usually happens when in the body of a function; each
statement is treated as a declaration-statement until proven
if (cp_parser_error_occurred (parser))
goto done;
- if (auto_node)
+ if (auto_result)
{
- tree type = TREE_TYPE (decl);
- if (last_type && !same_type_p (type, last_type))
+ if (last_type && last_type != error_mark_node
+ && !same_type_p (auto_result, last_type))
{
/* If the list of declarators contains more than one declarator,
the type of each declared variable is determined as described
the same in each deduction, the program is ill-formed. */
error_at (decl_specifiers.locations[ds_type_spec],
"inconsistent deduction for %qT: %qT and then %qT",
- decl_specifiers.type, last_type, type);
- auto_node = NULL_TREE;
+ decl_specifiers.type, last_type, auto_result);
+ last_type = error_mark_node;
}
- last_type = type;
+ else
+ last_type = auto_result;
}
/* Handle function definitions specially. */
}
}
+/* Given the type TYPE of a declaration with declarator DECLARATOR, return the
+ type that comes from the decl-specifier-seq. */
+
+static tree
+strip_declarator_types (tree type, cp_declarator *declarator)
+{
+ for (cp_declarator *d = declarator; d;)
+ switch (d->kind)
+ {
+ case cdk_id:
+ case cdk_error:
+ d = NULL;
+ break;
+
+ default:
+ if (TYPE_PTRMEMFUNC_P (type))
+ type = TYPE_PTRMEMFUNC_FN_TYPE (type);
+ type = TREE_TYPE (type);
+ d = d->declarator;
+ break;
+ }
+
+ return type;
+}
+
/* Declarators [gram.dcl.decl] */
/* Parse an init-declarator.
int declares_class_or_enum,
bool* function_definition_p,
tree* maybe_range_for_decl,
- location_t* init_loc)
+ location_t* init_loc,
+ tree* auto_result)
{
cp_token *token = NULL, *asm_spec_start_token = NULL,
*attributes_start_token = NULL;
finish_fully_implicit_template (parser, /*member_decl_opt=*/0);
}
+ if (auto_result && is_initialized && decl_specifiers->type
+ && type_uses_auto (decl_specifiers->type))
+ *auto_result = strip_declarator_types (TREE_TYPE (decl), declarator);
+
return decl;
}
member_p,
declares_class_or_enum,
&function_definition_p,
- NULL, NULL);
+ NULL, NULL, NULL);
/* 7.1.1-1 [dcl.stc]