static tree cp_parser_postfix_open_square_expression
(cp_parser *, tree, bool);
static tree cp_parser_postfix_dot_deref_expression
- (cp_parser *, enum cpp_ttype, tree, bool, cp_id_kind *);
+ (cp_parser *, enum cpp_ttype, tree, bool, cp_id_kind *, location_t);
static tree cp_parser_parenthesized_expression_list
(cp_parser *, bool, bool, bool, bool *);
static void cp_parser_pseudo_destructor_name
/* Utility Routines */
static tree cp_parser_lookup_name
- (cp_parser *, tree, enum tag_types, bool, bool, bool, tree *);
+ (cp_parser *, tree, enum tag_types, bool, bool, bool, tree *, location_t);
static tree cp_parser_lookup_name_simple
- (cp_parser *, tree);
+ (cp_parser *, tree, location_t);
static tree cp_parser_maybe_treat_template_as_class
(tree, bool);
static bool cp_parser_check_declarator_template_parameters
- (cp_parser *, cp_declarator *);
+ (cp_parser *, cp_declarator *, location_t);
static bool cp_parser_check_template_parameters
- (cp_parser *, unsigned);
+ (cp_parser *, unsigned, location_t);
static tree cp_parser_simple_cast_expression
(cp_parser *);
static tree cp_parser_global_scope_opt
static bool cp_parser_declares_only_class_p
(cp_parser *);
static void cp_parser_set_storage_class
- (cp_parser *, cp_decl_specifier_seq *, enum rid);
+ (cp_parser *, cp_decl_specifier_seq *, enum rid, location_t);
static void cp_parser_set_decl_spec_type
(cp_decl_specifier_seq *, tree, bool);
static bool cp_parser_friend_p
static void cp_parser_check_class_key
(enum tag_types, tree type);
static void cp_parser_check_access_in_redeclaration
- (tree type);
+ (tree type, location_t location);
static bool cp_parser_optional_template_keyword
(cp_parser *);
static void cp_parser_pre_parsed_nested_name_specifier
static void cp_parser_error
(cp_parser *, const char *);
static void cp_parser_name_lookup_error
- (cp_parser *, tree, tree, const char *);
+ (cp_parser *, tree, tree, const char *, location_t);
static bool cp_parser_simulate_error
(cp_parser *);
static bool cp_parser_check_type_definition
static bool cp_parser_non_integral_constant_expression
(cp_parser *, const char *);
static void cp_parser_diagnose_invalid_type_name
- (cp_parser *, tree, tree);
+ (cp_parser *, tree, tree, location_t);
static bool cp_parser_parse_and_diagnose_invalid_type_name
(cp_parser *);
static int cp_parser_skip_to_closing_parenthesis
static bool cp_parser_is_keyword
(cp_token *, enum rid);
static tree cp_parser_make_typename_type
- (cp_parser *, tree, tree);
+ (cp_parser *, tree, tree, location_t location);
static cp_declarator * cp_parser_make_indirect_declarator
(enum tree_code, tree, cp_cv_quals, cp_declarator *);
if (token->type == CPP_PRAGMA)
{
- error ("%<#pragma%> is not allowed here");
+ error ("%H%<#pragma%> is not allowed here", &token->location);
cp_parser_skip_to_pragma_eol (parser, token);
return;
}
cp_parser_name_lookup_error (cp_parser* parser,
tree name,
tree decl,
- const char* desired)
+ const char* desired,
+ location_t location)
{
/* If name lookup completely failed, tell the user that NAME was not
declared. */
if (decl == error_mark_node)
{
if (parser->scope && parser->scope != global_namespace)
- error ("%<%E::%E%> has not been declared",
- parser->scope, name);
+ error ("%H%<%E::%E%> has not been declared",
+ &location, parser->scope, name);
else if (parser->scope == global_namespace)
- error ("%<::%E%> has not been declared", name);
+ error ("%H%<::%E%> has not been declared", &location, name);
else if (parser->object_scope
&& !CLASS_TYPE_P (parser->object_scope))
- error ("request for member %qE in non-class type %qT",
- name, parser->object_scope);
+ error ("%Hrequest for member %qE in non-class type %qT",
+ &location, name, parser->object_scope);
else if (parser->object_scope)
- error ("%<%T::%E%> has not been declared",
- parser->object_scope, name);
+ error ("%H%<%T::%E%> has not been declared",
+ &location, parser->object_scope, name);
else
- error ("%qE has not been declared", name);
+ error ("%H%qE has not been declared", &location, name);
}
else if (parser->scope && parser->scope != global_namespace)
- error ("%<%E::%E%> %s", parser->scope, name, desired);
+ error ("%H%<%E::%E%> %s", &location, parser->scope, name, desired);
else if (parser->scope == global_namespace)
- error ("%<::%E%> %s", name, desired);
+ error ("%H%<::%E%> %s", &location, name, desired);
else
- error ("%qE %s", name, desired);
+ error ("%H%qE %s", &location, name, desired);
}
/* If we are parsing tentatively, remember that an error has occurred
/* Check for repeated decl-specifiers. */
static void
-cp_parser_check_decl_spec (cp_decl_specifier_seq *decl_specs)
+cp_parser_check_decl_spec (cp_decl_specifier_seq *decl_specs,
+ location_t location)
{
cp_decl_spec ds;
if (ds == ds_long)
{
if (count > 2)
- error ("%<long long long%> is too long for GCC");
+ error ("%H%<long long long%> is too long for GCC", &location);
else if (pedantic && !in_system_header && warn_long_long
&& cxx_dialect == cxx98)
- pedwarn ("ISO C++ 1998 does not support %<long long%>");
+ pedwarn ("%HISO C++ 1998 does not support %<long long%>",
+ &location);
}
else if (count > 1)
{
"__complex",
"__thread"
};
- error ("duplicate %qs", decl_spec_names[(int)ds]);
+ error ("%Hduplicate %qs", &location, decl_spec_names[(int)ds]);
}
}
}
in duplicate error messages.) */
static void
-cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree scope, tree id)
+cp_parser_diagnose_invalid_type_name (cp_parser *parser,
+ tree scope, tree id,
+ location_t id_location)
{
tree decl, old_scope;
/* Try to lookup the identifier. */
old_scope = parser->scope;
parser->scope = scope;
- decl = cp_parser_lookup_name_simple (parser, id);
+ decl = cp_parser_lookup_name_simple (parser, id, id_location);
parser->scope = old_scope;
/* If the lookup found a template-name, it means that the user forgot
to specify an argument list. Emit a useful error message. */
cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser)
{
tree id;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
cp_parser_parse_tentatively (parser);
id = cp_parser_id_expression (parser,
return false;
/* Emit a diagnostic for the invalid type. */
- cp_parser_diagnose_invalid_type_name (parser, parser->scope, id);
+ cp_parser_diagnose_invalid_type_name (parser, parser->scope,
+ id, token->location);
/* Skip to the end of the declaration; there's no point in
trying to process it. */
cp_parser_skip_to_end_of_block_or_statement (parser);
using cp_parser_diagnose_invalid_type_name. */
static tree
-cp_parser_make_typename_type (cp_parser *parser, tree scope, tree id)
+cp_parser_make_typename_type (cp_parser *parser, tree scope,
+ tree id, location_t id_location)
{
tree result;
if (TREE_CODE (id) == IDENTIFIER_NODE)
result = make_typename_type (scope, id, typename_type,
/*complain=*/tf_none);
if (result == error_mark_node)
- cp_parser_diagnose_invalid_type_name (parser, scope, id);
+ cp_parser_diagnose_invalid_type_name (parser, scope, id, id_location);
return result;
}
return make_typename_type (scope, id, typename_type, tf_error);
if (type == CPP_STRING)
type = tok->type;
else if (tok->type != CPP_STRING)
- error ("unsupported non-standard concatenation of string literals");
+ error ("%Hunsupported non-standard concatenation "
+ "of string literals", &tok->location);
}
obstack_grow (&str_ob, &str, sizeof (cpp_string));
bool template_arg_p,
cp_id_kind *idk)
{
- cp_token *token;
+ cp_token *token = NULL;
/* Assume the primary expression is not an id-expression. */
*idk = CP_ID_KIND_NONE;
{
/* Statement-expressions are not allowed by the standard. */
if (pedantic)
- pedwarn ("ISO C++ forbids braced-groups within expressions");
+ pedwarn ("%HISO C++ forbids braced-groups within expressions",
+ &token->location);
/* And they're not allowed outside of a function-body; you
cannot, for example, write:
if (!parser->in_function_body
|| parser->in_template_argument_list_p)
{
- error ("statement-expressions are not allowed outside "
- "functions nor in template-argument lists");
+ error ("%Hstatement-expressions are not allowed outside "
+ "functions nor in template-argument lists",
+ &token->location);
cp_parser_skip_to_end_of_block_or_statement (parser);
expr = error_mark_node;
}
cp_lexer_consume_token (parser->lexer);
if (parser->local_variables_forbidden_p)
{
- error ("%<this%> may not be used in this context");
+ error ("%H%<this%> may not be used in this context",
+ &token->location);
return error_mark_node;
}
/* Pointers cannot appear in constant-expressions. */
const char *error_msg;
bool template_p;
bool done;
+ cp_token *id_expr_token;
id_expression:
/* Parse the id-expression. */
/*optional_p=*/false);
if (id_expression == error_mark_node)
return error_mark_node;
+ id_expr_token = token;
token = cp_lexer_peek_token (parser->lexer);
done = (token->type != CPP_OPEN_SQUARE
&& token->type != CPP_OPEN_PAREN
template_p,
/*is_namespace=*/false,
/*check_dependency=*/true,
- &ambiguous_decls);
+ &ambiguous_decls,
+ id_expr_token->location);
/* If the lookup was ambiguous, an error will already have
been issued. */
if (ambiguous_decls)
decl = check_for_out_of_scope_variable (decl);
if (local_variable_p (decl))
{
- error ("local variable %qD may not appear in this context",
- decl);
+ error ("%Hlocal variable %qD may not appear in this context",
+ &id_expr_token->location, decl);
return error_mark_node;
}
}
&parser->non_integral_constant_expression_p,
template_p, done, address_p,
template_arg_p,
- &error_msg));
+ &error_msg,
+ id_expr_token->location));
if (error_msg)
cp_parser_error (parser, error_msg);
return decl;
if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
{
if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
- error ("scope %qT before %<~%> is not a class-name", scope);
+ error ("%Hscope %qT before %<~%> is not a class-name",
+ &token->location, scope);
cp_parser_simulate_error (parser);
if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
cp_lexer_consume_token (parser->lexer);
if (declarator_p && scope && !check_dtor_name (scope, type_decl))
{
if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
- error ("declaration of %<~%T%> as member of %qT",
- type_decl, scope);
+ error ("%Hdeclaration of %<~%T%> as member of %qT",
+ &token->location, type_decl, scope);
cp_parser_simulate_error (parser);
return error_mark_node;
}
&& !DECL_IMPLICIT_TYPEDEF_P (type_decl)
&& !DECL_SELF_REFERENCE_P (type_decl)
&& !cp_parser_uncommitted_to_tentative_parse_p (parser))
- error ("typedef-name %qD used as destructor declarator",
- type_decl);
+ error ("%Htypedef-name %qD used as destructor declarator",
+ &token->location, type_decl);
return build_nt (BIT_NOT_EXPR, TREE_TYPE (type_decl));
}
/*is_template=*/false,
/*is_namespace=*/false,
/*check_dependency=*/true,
- &ambiguous_decls);
+ &ambiguous_decls,
+ token->location);
if (TREE_CODE (decl) == TEMPLATE_DECL)
- error ("%qD used without template parameters", decl);
+ error ("%H%qD used without template parameters",
+ &token->location, decl);
else if (ambiguous_decls)
{
- error ("reference to %qD is ambiguous",
- token->u.value);
+ error ("%Hreference to %qD is ambiguous",
+ &token->location, token->u.value);
print_candidates (ambiguous_decls);
decl = error_mark_node;
}
else
cp_parser_name_lookup_error
(parser, token->u.value, decl,
- "is not a class or namespace");
+ "is not a class or namespace",
+ token->location);
}
parser->scope = error_mark_node;
error_p = true;
postfix_expression
= cp_parser_postfix_dot_deref_expression (parser, token->type,
postfix_expression,
- false, &idk);
+ false, &idk,
+ token->location);
is_member_access = true;
break;
cp_parser_postfix_dot_deref_expression (cp_parser *parser,
enum cpp_ttype token_type,
tree postfix_expression,
- bool for_offsetof, cp_id_kind *idk)
+ bool for_offsetof, cp_id_kind *idk,
+ location_t location)
{
tree name;
bool dependent_p;
/* The type of the POSTFIX_EXPRESSION must be complete. */
if (scope == unknown_type_node)
{
- error ("%qE does not have class type", postfix_expression);
+ error ("%H%qE does not have class type", &location, postfix_expression);
scope = NULL_TREE;
}
else
ordinary class member access expression, rather than a
pseudo-destructor-name. */
bool template_p;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
/* Parse the id-expression. */
name = (cp_parser_id_expression
(parser,
TYPE_DECL here. That is invalid code. */
if (TREE_CODE (name) == TYPE_DECL)
{
- error ("invalid use of %qD", name);
+ error ("%Hinvalid use of %qD", &token->location, name);
postfix_expression = error_mark_node;
}
else
type-id. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
+ cp_token *token;
/* Consume the `('. */
cp_lexer_consume_token (parser->lexer);
/* Parse the type-id. */
type = cp_parser_type_id (parser);
/* Look for the closing `)'. */
cp_parser_require (parser, CPP_CLOSE_PAREN, "%<)%>");
+ token = cp_lexer_peek_token (parser->lexer);
/* There should not be a direct-new-declarator in this production,
but GCC used to allowed this, so we check and emit a sensible error
message for this case. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
{
- error ("array bound forbidden after parenthesized type-id");
+ error ("%Harray bound forbidden after parenthesized type-id",
+ &token->location);
inform ("try removing the parentheses around the type-id");
cp_parser_direct_new_declarator (parser);
}
/* The first expression is not required to be constant. */
if (!declarator)
{
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
expression = cp_parser_expression (parser, /*cast_p=*/false);
/* The standard requires that the expression have integral
type. DR 74 adds enumeration types. We believe that the
/*complain=*/true);
if (!expression)
{
- error ("expression in new-declarator must have integral "
- "or enumeration type");
+ error ("%Hexpression in new-declarator must have integral "
+ "or enumeration type", &token->location);
expression = error_mark_node;
}
}
int save_ice_p, save_non_ice_p;
tree type, expr;
cp_id_kind dummy;
+ cp_token *token;
/* We're about to accept non-integral-constant things, but will
definitely yield an integral constant expression. Save and
type = cp_parser_type_id (parser);
/* Look for the `,'. */
cp_parser_require (parser, CPP_COMMA, "%<,%>");
+ token = cp_lexer_peek_token (parser->lexer);
/* Build the (type *)null that begins the traditional offsetof macro. */
expr = build_static_cast (build_pointer_type (type), null_pointer_node,
/* Parse the offsetof-member-designator. We begin as if we saw "expr->". */
expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DEREF, expr,
- true, &dummy);
+ true, &dummy, token->location);
while (true)
{
- cp_token *token = cp_lexer_peek_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
switch (token->type)
{
case CPP_OPEN_SQUARE:
/* offsetof-member-designator "." identifier */
cp_lexer_consume_token (parser->lexer);
expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DOT, expr,
- true, &dummy);
+ true, &dummy,
+ token->location);
break;
case CPP_CLOSE_PAREN:
if (parser->in_switch_statement_p)
finish_case_label (expr, expr_hi);
else
- error ("case label %qE not within a switch statement", expr);
+ error ("%Hcase label %qE not within a switch statement",
+ &token->location, expr);
}
break;
if (parser->in_switch_statement_p)
finish_case_label (NULL_TREE, NULL_TREE);
else
- error ("case label not within a switch statement");
+ error ("%Hcase label not within a switch statement", &token->location);
break;
default:
else
{
token = cp_lexer_consume_token (parser->lexer);
- error ("%<else%> without a previous %<if%>");
+ error ("%H%<else%> without a previous %<if%>", &token->location);
}
}
switch (in_statement)
{
case 0:
- error ("break statement not within loop or switch");
+ error ("%Hbreak statement not within loop or switch", &token->location);
break;
default:
gcc_assert ((in_statement & IN_SWITCH_STMT)
statement = finish_break_stmt ();
break;
case IN_OMP_BLOCK:
- error ("invalid exit from OpenMP structured block");
+ error ("%Hinvalid exit from OpenMP structured block", &token->location);
break;
case IN_OMP_FOR:
- error ("break statement used with OpenMP for loop");
+ error ("%Hbreak statement used with OpenMP for loop", &token->location);
break;
}
cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
switch (parser->in_statement & ~(IN_SWITCH_STMT | IN_IF_STMT))
{
case 0:
- error ("continue statement not within a loop");
+ error ("%Hcontinue statement not within a loop", &token->location);
break;
case IN_ITERATION_STMT:
case IN_OMP_FOR:
statement = finish_continue_stmt ();
break;
case IN_OMP_BLOCK:
- error ("invalid exit from OpenMP structured block");
+ error ("%Hinvalid exit from OpenMP structured block", &token->location);
break;
default:
gcc_unreachable ();
{
/* Issue a warning about this use of a GNU extension. */
if (pedantic)
- pedwarn ("ISO C++ forbids computed gotos");
+ pedwarn ("%HISO C++ forbids computed gotos", &token->location);
/* Consume the '*' token. */
cp_lexer_consume_token (parser->lexer);
/* Parse the dependent expression. */
else if (token1->keyword == RID_LABEL)
{
cp_lexer_consume_token (parser->lexer);
- error ("%<__label__%> not at the beginning of a block");
+ error ("%H%<__label__%> not at the beginning of a block", &token1->location);
cp_parser_skip_to_end_of_statement (parser);
/* If the next token is now a `;', consume it. */
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
which is erroneous. */
if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
- error ("mixing declarations and function-definitions is forbidden");
+ {
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ error ("%Hmixing declarations and function-definitions is forbidden",
+ &token->location);
+ }
/* Otherwise, we're done with the list of declarators. */
else
{
int* declares_class_or_enum)
{
bool constructor_possible_p = !parser->in_declarator_p;
+ cp_token *start_token = NULL;
/* Clear DECL_SPECS. */
clear_decl_specs (decl_specs);
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
+
+ /* Save the first token of the decl spec list for error
+ reporting. */
+ if (!start_token)
+ start_token = token;
/* Handle attributes. */
if (token->keyword == RID_ATTRIBUTE)
{
we're complaining about C++0x compatibility. */
warning
(OPT_Wc__0x_compat,
- "%<auto%> will change meaning in C++0x; please remove it");
+ "%H%<auto%> will change meaning in C++0x; please remove it",
+ &token->location);
/* Set the storage class anyway. */
- cp_parser_set_storage_class (parser, decl_specs, RID_AUTO);
+ cp_parser_set_storage_class (parser, decl_specs, RID_AUTO,
+ token->location);
}
else
/* We do not yet support the use of `auto' as a
type-specifier. */
- error ("C++0x %<auto%> specifier not supported");
+ error ("%HC++0x %<auto%> specifier not supported", &token->location);
break;
case RID_REGISTER:
case RID_MUTABLE:
/* Consume the token. */
cp_lexer_consume_token (parser->lexer);
- cp_parser_set_storage_class (parser, decl_specs, token->keyword);
+ cp_parser_set_storage_class (parser, decl_specs, token->keyword,
+ token->location);
break;
case RID_THREAD:
/* Consume the token. */
/*is_declaration=*/true,
&decl_spec_declares_class_or_enum,
&is_cv_qualifier);
-
*declares_class_or_enum |= decl_spec_declares_class_or_enum;
/* If this type-specifier referenced a user-defined type
flags |= CP_PARSER_FLAGS_OPTIONAL;
}
- cp_parser_check_decl_spec (decl_specs);
+ cp_parser_check_decl_spec (decl_specs, start_token->location);
/* Don't allow a friend specifier with a class definition. */
if (decl_specs->specs[(int) ds_friend] != 0
&& (*declares_class_or_enum & 2))
- error ("class definition may not be declared a friend");
+ error ("%Hclass definition may not be declared a friend",
+ &start_token->location);
}
/* Parse an (optional) storage-class-specifier.
cp_parser_function_specifier_opt (cp_parser* parser,
cp_decl_specifier_seq *decl_specs)
{
- switch (cp_lexer_peek_token (parser->lexer)->keyword)
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ switch (token->keyword)
{
case RID_INLINE:
if (decl_specs)
A member function template shall not be virtual. */
if (PROCESSING_REAL_TEMPLATE_DECL_P ())
- error ("templates may not be %<virtual%>");
+ error ("%Htemplates may not be %<virtual%>", &token->location);
else if (decl_specs)
++decl_specs->specs[(int) ds_virtual];
break;
const char *saved_message;
bool saved_integral_constant_expression_p;
bool saved_non_integral_constant_expression_p;
+ cp_token *id_expr_start_token;
/* Look for the `decltype' token. */
if (!cp_parser_require_keyword (parser, RID_DECLTYPE, "%<decltype%>"))
return error_mark_node;
/* First, try parsing an id-expression. */
+ id_expr_start_token = cp_lexer_peek_token (parser->lexer);
cp_parser_parse_tentatively (parser);
expr = cp_parser_id_expression (parser,
/*template_keyword_p=*/false,
/*is_template=*/false,
/*is_namespace=*/false,
/*check_dependency=*/true,
- /*ambiguous_decls=*/NULL);
+ /*ambiguous_decls=*/NULL,
+ id_expr_start_token->location);
if (expr
&& expr != error_mark_node
/*done=*/true,
/*address_p=*/false,
/*template_arg_p=*/false,
- &error_msg));
+ &error_msg,
+ id_expr_start_token->location));
if (expr == error_mark_node)
/* We found an id-expression, but it was something that we
cp_parser_mem_initializer_list (cp_parser* parser)
{
tree mem_initializer_list = NULL_TREE;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
/* Let the semantic analysis code know that we are starting the
mem-initializer-list. */
if (!DECL_CONSTRUCTOR_P (current_function_decl))
- error ("only constructors take base initializers");
+ error ("%Honly constructors take base initializers",
+ &token->location);
/* Loop through the list. */
while (true)
{
tree mem_initializer;
+ token = cp_lexer_peek_token (parser->lexer);
/* Parse the mem-initializer. */
mem_initializer = cp_parser_mem_initializer (parser);
/* If the next token is a `...', we're expanding member initializers. */
if (mem_initializer != error_mark_node
&& !TYPE_P (TREE_PURPOSE (mem_initializer)))
{
- error ("cannot expand initializer for member %<%D%>",
- TREE_PURPOSE (mem_initializer));
+ error ("%Hcannot expand initializer for member %<%D%>",
+ &token->location, TREE_PURPOSE (mem_initializer));
mem_initializer = error_mark_node;
}
tree mem_initializer_id;
tree expression_list;
tree member;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
/* Find out what is being initialized. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
- permerror ("anachronistic old-style base class initializer");
+ permerror ("%Hanachronistic old-style base class initializer",
+ &token->location);
mem_initializer_id = NULL_TREE;
}
else
bool template_p = false;
tree id;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+
/* `typename' is not allowed in this context ([temp.res]). */
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME))
{
- error ("keyword %<typename%> not allowed in this context (a qualified "
- "member initializer is implicitly a type)");
+ error ("%Hkeyword %<typename%> not allowed in this context (a qualified "
+ "member initializer is implicitly a type)",
+ &token->location);
cp_lexer_consume_token (parser->lexer);
}
/* Look for the optional `::' operator. */
appropriate diagnostic here. */
/* Consume the `='. */
+ cp_token *start_token = cp_lexer_peek_token (parser->lexer);
cp_lexer_consume_token (parser->lexer);
/* Find the name of the parameter pack. */
id_declarator = id_declarator->declarator;
if (id_declarator && id_declarator->kind == cdk_id)
- error ("template parameter pack %qD cannot have a default argument",
- id_declarator->u.id.unqualified_name);
+ error ("%Htemplate parameter pack %qD cannot have a default argument",
+ &start_token->location, id_declarator->u.id.unqualified_name);
else
- error ("template parameter pack cannot have a default argument");
+ error ("%Htemplate parameter pack cannot have a default argument",
+ &start_token->location);
/* Parse the default argument, but throw away the result. */
cp_parser_default_argument (parser, /*template_parm_p=*/true);
if (*is_parameter_pack)
{
if (identifier)
- error ("template parameter pack %qD cannot have a default argument",
- identifier);
+ error ("%Htemplate parameter pack %qD cannot have a "
+ "default argument", &token->location, identifier);
else
- error ("template parameter packs cannot have default arguments");
+ error ("%Htemplate parameter packs cannot have "
+ "default arguments", &token->location);
default_argument = NULL_TREE;
}
pop_deferring_access_checks ();
cp_lexer_consume_token (parser->lexer);
/* Parse the id-expression. */
push_deferring_access_checks (dk_no_deferred);
+ /* save token before parsing the id-expression, for error
+ reporting */
+ token = cp_lexer_peek_token (parser->lexer);
default_argument
= cp_parser_id_expression (parser,
/*template_keyword_p=*/false,
/*is_template=*/is_template,
/*is_namespace=*/false,
/*check_dependency=*/true,
- /*ambiguous_decls=*/NULL);
+ /*ambiguous_decls=*/NULL,
+ token->location);
/* See if the default argument is valid. */
default_argument
= check_template_template_default_arg (default_argument);
if (*is_parameter_pack)
{
if (identifier)
- error ("template parameter pack %qD cannot have a default argument",
- identifier);
+ error ("%Htemplate parameter pack %qD cannot "
+ "have a default argument",
+ &token->location, identifier);
else
- error ("template parameter packs cannot have default arguments");
+ error ("%Htemplate parameter packs cannot "
+ "have default arguments",
+ &token->location);
default_argument = NULL_TREE;
}
pop_deferring_access_checks ();
cp_token_position start_of_id = 0;
deferred_access_check *chk;
VEC (deferred_access_check,gc) *access_check;
- cp_token *next_token, *next_token_2;
+ cp_token *next_token = NULL, *next_token_2 = NULL, *token = NULL;
bool is_identifier;
/* If the next token corresponds to a template-id, there is no need
/* Parse the template-name. */
is_identifier = false;
+ token = cp_lexer_peek_token (parser->lexer);
template = cp_parser_template_name (parser, template_keyword_p,
check_dependency_p,
is_declaration,
/* Consume the first token (CPP_OPEN_SQUARE - which we pretend it is
CPP_LESS. */
cp_lexer_consume_token (parser->lexer);
+
/* Parse the arguments. */
arguments = cp_parser_enclosed_template_argument_list (parser);
if (!cp_parser_parse_definitely (parser))
}
/* Otherwise, emit an error about the invalid digraph, but continue
parsing because we got our argument list. */
- permerror ("%<<::%> cannot begin a template-argument list");
- inform ("%<<:%> is an alternate spelling for %<[%>. Insert whitespace "
- "between %<<%> and %<::%>");
+ permerror ("%H%<<::%> cannot begin a template-argument list",
+ &next_token->location);
+ inform ("%H%<<:%> is an alternate spelling for %<[%>. Insert whitespace "
+ "between %<<%> and %<::%>",
+ &next_token->location);
if (!flag_permissive)
{
static bool hint;
if (!hint)
{
- inform ("(if you use %<-fpermissive%> G++ will accept your code)");
+ inform ("%H(if you use %<-fpermissive%> G++ will accept your code)",
+ &next_token->location);
hint = true;
}
}
user, as opposed to simply marking the tentative parse as
failed? */
if (cp_parser_error_occurred (parser) && template_id != error_mark_node)
- error ("parse error in template argument list");
+ error ("%Hparse error in template argument list",
+ &token->location);
}
pop_deferring_access_checks ();
tree identifier;
tree decl;
tree fns;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
/* If the next token is `operator', then we have either an
operator-function-id or a conversion-function-id. */
cp_token_position start = 0;
/* Explain what went wrong. */
- error ("non-template %qD used as template", identifier);
+ error ("%Hnon-template %qD used as template",
+ &token->location, identifier);
inform ("use %<%T::template %D%> to indicate that it is a template",
parser->scope, identifier);
/* If parsing tentatively, find the location of the "<" token. */
/*is_template=*/false,
/*is_namespace=*/false,
check_dependency_p,
- /*ambiguous_decls=*/NULL);
+ /*ambiguous_decls=*/NULL,
+ token->location);
decl = maybe_get_template_decl_from_type_decl (decl);
/* If DECL is a template, then the name was a template-name. */
bool template_p;
bool address_p;
bool maybe_type_id = false;
- cp_token *token;
+ cp_token *token = NULL, *argument_start_token = NULL;
cp_id_kind idk;
/* There's really no way to know what we're looking at, so we just
/* We're still not sure what the argument will be. */
cp_parser_parse_tentatively (parser);
/* Try a template. */
+ argument_start_token = cp_lexer_peek_token (parser->lexer);
argument = cp_parser_id_expression (parser,
/*template_keyword_p=*/false,
/*check_dependency_p=*/true,
/*is_template=*/template_p,
/*is_namespace=*/false,
/*check_dependency=*/true,
- /*ambiguous_decls=*/NULL);
+ /*ambiguous_decls=*/NULL,
+ argument_start_token->location);
if (TREE_CODE (argument) != TEMPLATE_DECL
&& TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
cp_parser_error (parser, "expected template-name");
cp_parser_explicit_specialization (cp_parser* parser)
{
bool need_lang_pop;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+
/* Look for the `template' keyword. */
cp_parser_require_keyword (parser, RID_TEMPLATE, "%<template%>");
/* Look for the `<'. */
linkage. */
if (current_lang_name == lang_name_c)
{
- error ("template specialization with C linkage");
+ error ("%Htemplate specialization with C linkage", &token->location);
/* Give it C++ linkage to avoid confusing other parts of the
front end. */
push_lang_context (lang_name_cplusplus);
cp_lexer_consume_token (parser->lexer);
/* We do not yet support the use of `auto' as a
type-specifier. */
- error ("C++0x %<auto%> specifier not supported");
+ error ("%HC++0x %<auto%> specifier not supported", &token->location);
}
break;
tree type_decl;
tree identifier;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
identifier = cp_parser_identifier (parser);
if (identifier == error_mark_node)
return error_mark_node;
/* Look up the type-name. */
- type_decl = cp_parser_lookup_name_simple (parser, identifier);
+ type_decl = cp_parser_lookup_name_simple (parser, identifier, token->location);
if (TREE_CODE (type_decl) != TYPE_DECL
&& (objc_is_id (identifier) || objc_is_class_name (identifier)))
{
if (!cp_parser_simulate_error (parser))
cp_parser_name_lookup_error (parser, identifier, type_decl,
- "is not a type");
+ "is not a type", token->location);
return error_mark_node;
}
/* Remember that the name was used in the definition of the
tree identifier;
tree type = NULL_TREE;
tree attributes = NULL_TREE;
+ cp_token *token = NULL;
/* See if we're looking at the `enum' keyword. */
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_ENUM))
if (!template_p)
cp_parser_parse_tentatively (parser);
/* Parse the template-id. */
+ token = cp_lexer_peek_token (parser->lexer);
decl = cp_parser_template_id (parser, template_p,
/*check_dependency_p=*/true,
is_declaration);
if (!type)
{
+ token = cp_lexer_peek_token (parser->lexer);
identifier = cp_parser_identifier (parser);
if (identifier == error_mark_node)
if (tag_type == typename_type
&& TREE_CODE (parser->scope) != NAMESPACE_DECL)
return cp_parser_make_typename_type (parser, parser->scope,
- identifier);
+ identifier,
+ token->location);
/* Look up a qualified name in the usual way. */
if (parser->scope)
{
/*is_template=*/false,
/*is_namespace=*/false,
/*check_dependency=*/true,
- &ambiguous_decls);
+ &ambiguous_decls,
+ token->location);
/* If the lookup was ambiguous, an error will already have been
issued. */
{
cp_parser_diagnose_invalid_type_name (parser,
parser->scope,
- identifier);
+ identifier,
+ token->location);
return error_mark_node;
}
/* An unqualified name was used to reference this type, so
there were no qualifying templates. */
if (!cp_parser_check_template_parameters (parser,
- /*num_templates=*/0))
+ /*num_templates=*/0,
+ token->location))
return error_mark_node;
type = xref_tag (tag_type, identifier, ts, template_p);
}
tree identifier;
tree namespace_decl;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+
/* Get the name of the namespace. */
identifier = cp_parser_identifier (parser);
if (identifier == error_mark_node)
/*is_template=*/false,
/*is_namespace=*/true,
/*check_dependency=*/true,
- /*ambiguous_decls=*/NULL);
+ /*ambiguous_decls=*/NULL,
+ token->location);
/* If it's not a namespace, issue an error. */
if (namespace_decl == error_mark_node
|| TREE_CODE (namespace_decl) != NAMESPACE_DECL)
{
if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
- error ("%qD is not a namespace-name", identifier);
+ error ("%H%qD is not a namespace-name", &token->location, identifier);
cp_parser_error (parser, "expected namespace-name");
namespace_decl = error_mark_node;
}
tree identifier;
tree namespace_specifier;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+
/* Look for the `namespace' keyword. */
cp_parser_require_keyword (parser, RID_NAMESPACE, "%<namespace%>");
/* Look for the identifier. */
if (!cp_parser_uncommitted_to_tentative_parse_p (parser)
&& cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
{
- error ("%<namespace%> definition is not allowed here");
+ error ("%H%<namespace%> definition is not allowed here", &token->location);
/* Skip the definition. */
cp_lexer_consume_token (parser->lexer);
if (cp_parser_skip_to_closing_brace (parser))
cp_parser_parse_definitely will be false, as required. */
return cp_parser_parse_definitely (parser);
+ token = cp_lexer_peek_token (parser->lexer);
/* Parse the unqualified-id. */
identifier = cp_parser_unqualified_id (parser,
/*template_keyword_p=*/false,
/* [namespace.udecl]
A using declaration shall not name a template-id. */
- error ("a template-id may not appear in a using-declaration");
+ error ("%Ha template-id may not appear in a using-declaration",
+ &token->location);
else
{
if (at_class_scope_p ())
}
else
{
- decl = cp_parser_lookup_name_simple (parser, identifier);
+ decl = cp_parser_lookup_name_simple (parser,
+ identifier,
+ token->location);
if (decl == error_mark_node)
- cp_parser_name_lookup_error (parser, identifier, decl, NULL);
+ cp_parser_name_lookup_error (parser, identifier,
+ decl, NULL,
+ token->location);
else if (check_for_bare_parameter_packs (decl))
return false;
else if (!at_namespace_scope_p ())
int declares_class_or_enum,
bool* function_definition_p)
{
- cp_token *token;
+ cp_token *token = NULL, *asm_spec_start_token = NULL,
+ *attributes_start_token = NULL;
cp_declarator *declarator;
tree prefix_attributes;
tree attributes;
resume_deferring_access_checks ();
/* Parse the declarator. */
+ token = cp_lexer_peek_token (parser->lexer);
declarator
= cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
&ctor_dtor_or_conv_p,
return error_mark_node;
/* Check that the number of template-parameter-lists is OK. */
- if (!cp_parser_check_declarator_template_parameters (parser, declarator))
+ if (!cp_parser_check_declarator_template_parameters (parser, declarator,
+ token->location))
return error_mark_node;
if (declares_class_or_enum & 2)
if (cp_parser_allow_gnu_extensions_p (parser))
{
/* Look for an asm-specification. */
+ asm_spec_start_token = cp_lexer_peek_token (parser->lexer);
asm_specification = cp_parser_asm_specification_opt (parser);
/* And attributes. */
+ attributes_start_token = cp_lexer_peek_token (parser->lexer);
attributes = cp_parser_attributes_opt (parser);
}
else
/* Neither attributes nor an asm-specification are allowed
on a function-definition. */
if (asm_specification)
- error ("an asm-specification is not allowed on a function-definition");
+ error ("%Han asm-specification is not allowed "
+ "on a function-definition",
+ &asm_spec_start_token->location);
if (attributes)
- error ("attributes are not allowed on a function-definition");
+ error ("%Hattributes are not allowed on a function-definition",
+ &attributes_start_token->location);
/* This is a function-definition. */
*function_definition_p = true;
{
if (function_declarator_p (declarator))
{
+ cp_token *initializer_start_token = cp_lexer_peek_token (parser->lexer);
if (initialization_kind == CPP_EQ)
initializer = cp_parser_pure_specifier (parser);
else
know what the user intended, so just silently
consume the initializer. */
if (decl != error_mark_node)
- error ("initializer provided for function");
+ error ("%Hinitializer provided for function",
+ &initializer_start_token->location);
cp_parser_skip_to_closing_parenthesis (parser,
/*recovering=*/true,
/*or_comma=*/false,
in function scopes. */
else if (!parser->in_function_body)
{
- error ("array bound is not an integer constant");
+ error ("%Harray bound is not an integer constant",
+ &token->location);
bounds = error_mark_node;
}
}
special_function_kind sfk;
bool abstract_ok;
bool pack_expansion_p = false;
+ cp_token *declarator_id_start_token;
/* Parse a declarator-id */
abstract_ok = (dcl_kind == CP_PARSER_DECLARATOR_EITHER);
}
}
+ declarator_id_start_token = cp_lexer_peek_token (parser->lexer);
unqualified_name
= cp_parser_declarator_id (parser, /*optional_p=*/abstract_ok);
qualifying_scope = parser->scope;
/*only_current_p=*/false);
/* If that failed, the declarator is invalid. */
if (TREE_CODE (type) == TYPENAME_TYPE)
- error ("%<%T::%E%> is not a type",
+ error ("%H%<%T::%E%> is not a type",
+ &declarator_id_start_token->location,
TYPE_CONTEXT (qualifying_scope),
TYPE_IDENTIFIER (qualifying_scope));
qualifying_scope = type;
if (qualifying_scope
&& CLASSTYPE_USE_TEMPLATE (name_type))
{
- error ("invalid use of constructor as a template");
+ error ("%Hinvalid use of constructor as a template",
+ &declarator_id_start_token->location);
inform ("use %<%T::%D%> instead of %<%T::%D%> to "
"name the constructor in a qualified name",
class_type,
cp_parser_global_scope_opt (parser,
/*current_scope_valid_p=*/false);
/* Look for the nested-name specifier. */
+ token = cp_lexer_peek_token (parser->lexer);
cp_parser_nested_name_specifier (parser,
/*typename_keyword_p=*/false,
/*check_dependency_p=*/true,
code = INDIRECT_REF;
if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
- error ("%qD is a namespace", parser->scope);
+ error ("%H%qD is a namespace", &token->location, parser->scope);
else
{
/* The type of which the member is a member is given by the
if (cv_quals & cv_qualifier)
{
- error ("duplicate cv-qualifier");
+ error ("%Hduplicate cv-qualifier", &token->location);
cp_lexer_purge_token (parser->lexer);
}
else
{
bool seen_type_specifier = false;
cp_parser_flags flags = CP_PARSER_FLAGS_OPTIONAL;
+ cp_token *start_token = NULL;
/* Clear the TYPE_SPECIFIER_SEQ. */
clear_decl_specs (type_specifier_seq);
continue;
}
+ /* record the token of the beginning of the type specifier seq,
+ for error reporting purposes*/
+ if (!start_token)
+ start_token = cp_lexer_peek_token (parser->lexer);
+
/* Look for the type-specifier. */
type_specifier = cp_parser_type_specifier (parser,
flags,
flags |= CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES;
}
- cp_parser_check_decl_spec (type_specifier_seq);
+ cp_parser_check_decl_spec (type_specifier_seq, start_token->location);
}
/* Parse a parameter-declaration-clause.
cp_decl_specifier_seq decl_specifiers;
cp_declarator *declarator;
tree default_argument;
- cp_token *token;
+ cp_token *token = NULL, *declarator_token_start = NULL;
const char *saved_message;
/* In a template parameter, `>' is not an operator.
&& cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
cp_parser_commit_to_tentative_parse (parser);
/* Parse the declarator. */
+ declarator_token_start = token;
declarator = cp_parser_declarator (parser,
CP_PARSER_DECLARATOR_EITHER,
/*ctor_dtor_or_conv_p=*/NULL,
/* If we run out of tokens, issue an error message. */
case CPP_EOF:
case CPP_PRAGMA_EOL:
- error ("file ends in default argument");
+ error ("%Hfile ends in default argument", &token->location);
done = true;
break;
/* Outside of a class definition, we can just parse the
assignment-expression. */
else
- default_argument
- = cp_parser_default_argument (parser, template_parm_p);
+ {
+ token = cp_lexer_peek_token (parser->lexer);
+ default_argument
+ = cp_parser_default_argument (parser, template_parm_p);
+ }
if (!parser->default_arg_ok_p)
{
warning (0, "deprecated use of default argument for parameter of non-function");
else
{
- error ("default arguments are only permitted for function parameters");
+ error ("%Hdefault arguments are only "
+ "permitted for function parameters",
+ &token->location);
default_argument = NULL_TREE;
}
}
id_declarator = id_declarator->declarator;
if (id_declarator && id_declarator->kind == cdk_id)
- error ("%sparameter pack %qD cannot have a default argument",
+ error ("%H%sparameter pack %qD cannot have a default argument",
+ &declarator_token_start->location,
kind, id_declarator->u.id.unqualified_name);
else
- error ("%sparameter pack cannot have a default argument",
- kind);
+ error ("%H%sparameter pack cannot have a default argument",
+ &declarator_token_start->location, kind);
default_argument = NULL_TREE;
}
/*is_template=*/false,
/*is_namespace=*/false,
check_dependency_p,
- &ambiguous_decls);
+ &ambiguous_decls,
+ identifier_token->location);
if (ambiguous_decls)
{
- error ("reference to %qD is ambiguous", identifier);
+ error ("%Hreference to %qD is ambiguous",
+ &identifier_token->location, identifier);
print_candidates (ambiguous_decls);
if (cp_parser_parsing_tentatively (parser))
{
bool invalid_explicit_specialization_p = false;
tree pushed_scope = NULL_TREE;
unsigned num_templates;
-
+ cp_token *type_start_token = NULL, *nested_name_specifier_token_start = NULL;
/* Assume no nested-name-specifier will be present. */
*nested_name_specifier_p = false;
/* Assume no template parameter lists will be used in defining the
/* Determine the name of the class. Begin by looking for an
optional nested-name-specifier. */
+ nested_name_specifier_token_start = cp_lexer_peek_token (parser->lexer);
nested_name_specifier
= cp_parser_nested_name_specifier_opt (parser,
/*typename_keyword_p=*/false,
identifier. */
if (nested_name_specifier)
{
+ type_start_token = cp_lexer_peek_token (parser->lexer);
/* Although the grammar says `identifier', it really means
`class-name' or `template-name'. You are only allowed to
define a class that has already been declared with this
an identifier, or nothing at all. */
cp_parser_parse_tentatively (parser);
/* Check for a template-id. */
+ type_start_token = cp_lexer_peek_token (parser->lexer);
id = cp_parser_template_id (parser,
/*template_keyword_p=*/false,
/*check_dependency_p=*/true,
/* Reject typedef-names in class heads. */
if (!DECL_IMPLICIT_TYPEDEF_P (type))
{
- error ("invalid class name in declaration of %qD", type);
+ error ("%Hinvalid class name in declaration of %qD",
+ &type_start_token->location, type);
type = NULL_TREE;
goto done;
}
if (scope && !is_ancestor (scope, nested_name_specifier))
{
if (at_namespace_scope_p ())
- error ("declaration of %qD in namespace %qD which does not "
- "enclose %qD", type, scope, nested_name_specifier);
+ error ("%Hdeclaration of %qD in namespace %qD which does not "
+ "enclose %qD",
+ &type_start_token->location,
+ type, scope, nested_name_specifier);
else
- error ("declaration of %qD in %qD which does not enclose %qD",
+ error ("%Hdeclaration of %qD in %qD which does not enclose %qD",
+ &type_start_token->location,
type, scope, nested_name_specifier);
type = NULL_TREE;
goto done;
class member of a namespace outside of its namespace. */
if (scope == nested_name_specifier)
{
- permerror ("extra qualification not allowed");
+ permerror ("%Hextra qualification not allowed",
+ &nested_name_specifier_token_start->location);
nested_name_specifier = NULL_TREE;
num_templates = 0;
}
&& parser->num_template_parameter_lists == 0
&& template_id_p)
{
- error ("an explicit specialization must be preceded by %<template <>%>");
+ error ("%Han explicit specialization must be preceded by %<template <>%>",
+ &type_start_token->location);
invalid_explicit_specialization_p = true;
/* Take the same action that would have been taken by
cp_parser_explicit_specialization. */
use "goto done;" to return. */
/* Make sure that the right number of template parameters were
present. */
- if (!cp_parser_check_template_parameters (parser, num_templates))
+ if (!cp_parser_check_template_parameters (parser, num_templates,
+ type_start_token->location))
{
/* If something went wrong, there is no point in even trying to
process the class-definition. */
&& (DECL_FUNCTION_TEMPLATE_P (TREE_OPERAND (id, 0))
|| TREE_CODE (TREE_OPERAND (id, 0)) == OVERLOAD))
{
- error ("function template %qD redeclared as a class template", id);
+ error ("%Hfunction template %qD redeclared as a class template",
+ &type_start_token->location, id);
type = error_mark_node;
}
else
that's an error. */
if (type != error_mark_node && COMPLETE_TYPE_P (type))
{
- error ("redefinition of %q#T", type);
- error ("previous definition of %q+#T", type);
+ error ("%Hredefinition of %q#T",
+ &type_start_token->location, type);
+ error ("%Hprevious definition of %q+#T",
+ &type_start_token->location, type);
type = NULL_TREE;
goto done;
}
tree decl;
int declares_class_or_enum;
bool friend_p;
- cp_token *token;
+ cp_token *token = NULL;
+ cp_token *decl_spec_token_start = NULL;
+ cp_token *initializer_token_start = NULL;
int saved_pedantic;
/* Check for the `__extension__' keyword. */
return;
/* Parse the decl-specifier-seq. */
+ decl_spec_token_start = cp_lexer_peek_token (parser->lexer);
cp_parser_decl_specifier_seq (parser,
CP_PARSER_FLAGS_OPTIONAL,
&decl_specifiers,
/* If the `friend' keyword was present, the friend must
be introduced with a class-key. */
if (!declares_class_or_enum)
- error ("a class-key must be used when declaring a friend");
+ error ("%Ha class-key must be used when declaring a friend",
+ &decl_spec_token_start->location);
/* In this case:
template <typename T> struct A {
&& TYPE_P (decl_specifiers.type))
type = decl_specifiers.type;
if (!type || !TYPE_P (type))
- error ("friend declaration does not name a class or "
- "function");
+ error ("%Hfriend declaration does not name a class or "
+ "function", &decl_spec_token_start->location);
else
make_friend_class (current_class_type, type,
/*complain=*/true);
finish_member_declaration (decl);
}
else
- cp_parser_check_access_in_redeclaration (TYPE_NAME (type));
+ cp_parser_check_access_in_redeclaration
+ (TYPE_NAME (type),
+ decl_spec_token_start->location);
}
}
else
for a pure-specifier; otherwise, we look for a
constant-initializer. When we call `grokfield', it will
perform more stringent semantics checks. */
+ initializer_token_start = cp_lexer_peek_token (parser->lexer);
if (function_declarator_p (declarator))
initializer = cp_parser_pure_specifier (parser);
else
standard, since a pure function may be defined
outside of the class-specifier. */
if (initializer)
- error ("pure-specifier on function-definition");
+ error ("%Hpure-specifier on function-definition",
+ &initializer_token_start->location);
decl = cp_parser_save_member_function_body (parser,
&decl_specifiers,
declarator,
}
if (PROCESSING_REAL_TEMPLATE_DECL_P ())
{
- error ("templates may not be %<virtual%>");
+ error ("%Htemplates may not be %<virtual%>", &token->location);
return error_mark_node;
}
as base classes. */
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME))
{
+ token = cp_lexer_peek_token (parser->lexer);
if (!processing_template_decl)
- error ("keyword %<typename%> not allowed outside of templates");
+ error ("%Hkeyword %<typename%> not allowed outside of templates",
+ &token->location);
else
- error ("keyword %<typename%> not allowed in this context "
- "(the base class is implicitly a type)");
+ error ("%Hkeyword %<typename%> not allowed in this context "
+ "(the base class is implicitly a type)",
+ &token->location);
cp_lexer_consume_token (parser->lexer);
}
bool is_template,
bool is_namespace,
bool check_dependency,
- tree *ambiguous_decls)
+ tree *ambiguous_decls,
+ location_t name_location)
{
int flags = 0;
tree decl;
cp_parser_error, so we incorporate its actions directly. */
if (!cp_parser_simulate_error (parser))
{
- error ("reference to %qD is ambiguous", name);
+ error ("%Hreference to %qD is ambiguous",
+ &name_location, name);
print_candidates (decl);
}
return error_mark_node;
IS_NAMESPACE is FALSE, and CHECK_DEPENDENCY is TRUE. */
static tree
-cp_parser_lookup_name_simple (cp_parser* parser, tree name)
+cp_parser_lookup_name_simple (cp_parser* parser, tree name, location_t location)
{
return cp_parser_lookup_name (parser, name,
none_type,
/*is_template=*/false,
/*is_namespace=*/false,
/*check_dependency=*/true,
- /*ambiguous_decls=*/NULL);
+ /*ambiguous_decls=*/NULL,
+ location);
}
/* If DECL is a TEMPLATE_DECL that can be treated like a TYPE_DECL in
static bool
cp_parser_check_declarator_template_parameters (cp_parser* parser,
- cp_declarator *declarator)
+ cp_declarator *declarator,
+ location_t declarator_location)
{
unsigned num_templates;
++num_templates;
return cp_parser_check_template_parameters (parser,
- num_templates);
+ num_templates,
+ declarator_location);
case cdk_function:
case cdk_array:
case cdk_reference:
case cdk_ptrmem:
return (cp_parser_check_declarator_template_parameters
- (parser, declarator->declarator));
+ (parser, declarator->declarator, declarator_location));
case cdk_error:
return true;
static bool
cp_parser_check_template_parameters (cp_parser* parser,
- unsigned num_templates)
+ unsigned num_templates,
+ location_t location)
{
/* If there are more template classes than parameter lists, we have
something like:
template <class T> void S<T>::R<T>::f (); */
if (parser->num_template_parameter_lists < num_templates)
{
- error ("too few template-parameter-lists");
+ error ("%Htoo few template-parameter-lists", &location);
return false;
}
/* If there are the same number of template classes and parameter
something like:
template <class T> template <class U> void S::f(); */
- error ("too many template-parameter-lists");
+ error ("%Htoo many template-parameter-lists", &location);
return false;
}
bool saved_in_unbraced_linkage_specification_p;
bool saved_in_function_body;
unsigned saved_num_template_parameter_lists;
+ cp_token *token;
saved_in_function_body = parser->in_function_body;
parser->in_function_body = true;
/* If the next token is `return', then the code may be trying to
make use of the "named return value" extension that G++ used to
support. */
+ token = cp_lexer_peek_token (parser->lexer);
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_RETURN))
{
/* Consume the `return' keyword. */
returned. */
cp_parser_identifier (parser);
/* Issue an error message. */
- error ("named return values are no longer supported");
+ error ("%Hnamed return values are no longer supported",
+ &token->location);
/* Skip tokens until we reach the start of the function body. */
while (true)
{
tree parameter_list;
bool friend_p = false;
bool need_lang_pop;
+ cp_token *token;
/* Look for the `template' keyword. */
+ token = cp_lexer_peek_token (parser->lexer);
if (!cp_parser_require_keyword (parser, RID_TEMPLATE, "%<template%>"))
return;
/* 14.5.2.2 [temp.mem]
A local class shall not have member templates. */
- error ("invalid declaration of member template in local class");
+ error ("%Hinvalid declaration of member template in local class",
+ &token->location);
cp_parser_skip_to_end_of_block_or_statement (parser);
return;
}
A template ... shall not have C linkage. */
if (current_lang_name == lang_name_c)
{
- error ("template with C linkage");
+ error ("%Htemplate with C linkage", &token->location);
/* Give it C++ linkage to avoid confusing other parts of the
front end. */
push_lang_context (lang_name_cplusplus);
/* There are no access checks when parsing a template, as we do not
know if a specialization will be a friend. */
push_deferring_access_checks (dk_no_check);
+ token = cp_lexer_peek_token (parser->lexer);
decl = cp_parser_single_declaration (parser,
checks,
member_p,
if (member_p && !friend_p && decl)
{
if (TREE_CODE (decl) == TYPE_DECL)
- cp_parser_check_access_in_redeclaration (decl);
+ cp_parser_check_access_in_redeclaration (decl, token->location);
decl = finish_member_template_decl (decl);
}
tree decl = NULL_TREE;
cp_decl_specifier_seq decl_specifiers;
bool function_definition_p = false;
+ cp_token *decl_spec_token_start;
/* This function is only used when processing a template
declaration. */
/* Try the `decl-specifier-seq [opt] init-declarator [opt]'
alternative. */
+ decl_spec_token_start = cp_lexer_peek_token (parser->lexer);
cp_parser_decl_specifier_seq (parser,
CP_PARSER_FLAGS_OPTIONAL,
&decl_specifiers,
/* There are no template typedefs. */
if (decl_specifiers.specs[(int) ds_typedef])
{
- error ("template declaration of %qs", "typedef");
+ error ("%Htemplate declaration of %qs",
+ &decl_spec_token_start->location, "typedef");
decl = error_mark_node;
}
&& explicit_specialization_p
&& decl_specifiers.storage_class != sc_none)
{
- error ("explicit template specialization cannot have a storage class");
+ error ("%Hexplicit template specialization cannot have a storage class",
+ &decl_spec_token_start->location);
decl = error_mark_node;
}
}
is a typo for '>'. Emit an error message and continue.
Same deal about the token location, but here we can get it
right by consuming the '>>' before issuing the diagnostic. */
- cp_lexer_consume_token (parser->lexer);
- error ("spurious %<>>%>, use %<>%> to terminate "
- "a template argument list");
+ cp_token *token = cp_lexer_consume_token (parser->lexer);
+ error ("%Hspurious %<>>%>, use %<>%> to terminate "
+ "a template argument list", &token->location);
}
}
else
static void
cp_parser_set_storage_class (cp_parser *parser,
cp_decl_specifier_seq *decl_specs,
- enum rid keyword)
+ enum rid keyword,
+ location_t location)
{
cp_storage_class storage_class;
if (parser->in_unbraced_linkage_specification_p)
{
- error ("invalid use of %qD in linkage specification",
- ridpointers[keyword]);
+ error ("%Hinvalid use of %qD in linkage specification",
+ &location, ridpointers[keyword]);
return;
}
else if (decl_specs->storage_class != sc_none)
if ((keyword == RID_EXTERN || keyword == RID_STATIC)
&& decl_specs->specs[(int) ds_thread])
{
- error ("%<__thread%> before %qD", ridpointers[keyword]);
+ error ("%H%<__thread%> before %qD", &location, ridpointers[keyword]);
decl_specs->specs[(int) ds_thread] = 0;
}
[class.mem/1]. */
static void
-cp_parser_check_access_in_redeclaration (tree decl)
+cp_parser_check_access_in_redeclaration (tree decl, location_t location)
{
if (!decl || !CLASS_TYPE_P (TREE_TYPE (decl)))
return;
!= (current_access_specifier == access_private_node))
|| (TREE_PROTECTED (decl)
!= (current_access_specifier == access_protected_node)))
- error ("%qD redeclared with different access", decl);
+ error ("%H%qD redeclared with different access", &location, decl);
}
/* Look for the `template' keyword, as a syntactic disambiguator.
template and what is not. */
if (!processing_template_decl)
{
- error ("%<template%> (as a disambiguator) is only allowed "
- "within templates");
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ error ("%H%<template%> (as a disambiguator) is only allowed "
+ "within templates", &token->location);
/* If this part of the token stream is rescanned, the same
error message would be generated. So, we purge the token
from the stream. */
break;
}
default:
- error ("misplaced %<@%D%> Objective-C++ construct", kwd->u.value);
+ error ("%Hmisplaced %<@%D%> Objective-C++ construct",
+ &kwd->location, kwd->u.value);
cp_parser_skip_to_end_of_block_or_statement (parser);
}
cp_parser_objc_encode_expression (cp_parser* parser)
{
tree type;
+ cp_token *token;
cp_lexer_consume_token (parser->lexer); /* Eat '@encode'. */
cp_parser_require (parser, CPP_OPEN_PAREN, "%<(%>");
+ token = cp_lexer_peek_token (parser->lexer);
type = complete_type (cp_parser_type_id (parser));
cp_parser_require (parser, CPP_CLOSE_PAREN, "%<)%>");
if (!type)
{
- error ("%<@encode%> must specify a type as an argument");
+ error ("%H%<@encode%> must specify a type as an argument",
+ &token->location);
return error_mark_node;
}
if (!cp_parser_objc_selector_p (token->type))
{
- error ("invalid Objective-C++ selector name");
+ error ("%Hinvalid Objective-C++ selector name", &token->location);
return error_mark_node;
}
cp_lexer_consume_token (parser->lexer); /* Eat '@protocol'. */
if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME))
{
- error ("identifier expected after %<@protocol%>");
+ tok = cp_lexer_peek_token (parser->lexer);
+ error ("%Hidentifier expected after %<@protocol%>", &tok->location);
goto finish;
}
cp_parser_objc_end_implementation (parser);
break;
default:
- error ("misplaced %<@%D%> Objective-C++ construct", kwd->u.value);
+ error ("%Hmisplaced %<@%D%> Objective-C++ construct",
+ &kwd->location, kwd->u.value);
cp_parser_skip_to_end_of_block_or_statement (parser);
}
}
case RID_AT_THROW:
return cp_parser_objc_throw_statement (parser);
default:
- error ("misplaced %<@%D%> Objective-C++ construct", kwd->u.value);
+ error ("%Hmisplaced %<@%D%> Objective-C++ construct",
+ &kwd->location, kwd->u.value);
cp_parser_skip_to_end_of_block_or_statement (parser);
}
/* Validate that a clause of the given type does not already exist. */
static void
-check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
+check_no_duplicate_clause (tree clauses, enum tree_code code,
+ const char *name, location_t location)
{
tree c;
for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
if (OMP_CLAUSE_CODE (c) == code)
{
- error ("too many %qs clauses", name);
+ error ("%Htoo many %qs clauses", &location, name);
break;
}
}
cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind,
tree list)
{
+ cp_token *token;
while (1)
{
tree name, decl;
+ token = cp_lexer_peek_token (parser->lexer);
name = cp_parser_id_expression (parser, /*template_p=*/false,
/*check_dependency_p=*/true,
/*template_p=*/NULL,
if (name == error_mark_node)
goto skip_comma;
- decl = cp_parser_lookup_name_simple (parser, name);
+ decl = cp_parser_lookup_name_simple (parser, name, token->location);
if (decl == error_mark_node)
- cp_parser_name_lookup_error (parser, name, decl, NULL);
+ cp_parser_name_lookup_error (parser, name, decl, NULL, token->location);
else if (kind != 0)
{
tree u = build_omp_clause (kind);
collapse ( constant-expression ) */
static tree
-cp_parser_omp_clause_collapse (cp_parser *parser, tree list)
+cp_parser_omp_clause_collapse (cp_parser *parser, tree list, location_t location)
{
tree c, num;
location_t loc;
|| (n = tree_low_cst (num, 0)) <= 0
|| (int) n != n)
{
- error ("%Hcollapse argument needs positive constant integer expression", &loc);
+ error ("%Hcollapse argument needs positive constant integer expression",
+ &loc);
return list;
}
- check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
+ check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse", location);
c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
OMP_CLAUSE_CHAIN (c) = list;
OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
default ( shared | none ) */
static tree
-cp_parser_omp_clause_default (cp_parser *parser, tree list)
+cp_parser_omp_clause_default (cp_parser *parser, tree list, location_t location)
{
enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
tree c;
if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
return list;
- check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
+ check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default", location);
c = build_omp_clause (OMP_CLAUSE_DEFAULT);
OMP_CLAUSE_CHAIN (c) = list;
OMP_CLAUSE_DEFAULT_KIND (c) = kind;
if ( expression ) */
static tree
-cp_parser_omp_clause_if (cp_parser *parser, tree list)
+cp_parser_omp_clause_if (cp_parser *parser, tree list, location_t location)
{
tree t, c;
/*or_comma=*/false,
/*consume_paren=*/true);
- check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
+ check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if", location);
c = build_omp_clause (OMP_CLAUSE_IF);
OMP_CLAUSE_IF_EXPR (c) = t;
nowait */
static tree
-cp_parser_omp_clause_nowait (cp_parser *parser ATTRIBUTE_UNUSED, tree list)
+cp_parser_omp_clause_nowait (cp_parser *parser ATTRIBUTE_UNUSED,
+ tree list, location_t location)
{
tree c;
- check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
+ check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait", location);
c = build_omp_clause (OMP_CLAUSE_NOWAIT);
OMP_CLAUSE_CHAIN (c) = list;
num_threads ( expression ) */
static tree
-cp_parser_omp_clause_num_threads (cp_parser *parser, tree list)
+cp_parser_omp_clause_num_threads (cp_parser *parser, tree list,
+ location_t location)
{
tree t, c;
/*or_comma=*/false,
/*consume_paren=*/true);
- check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
+ check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS,
+ "num_threads", location);
c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
ordered */
static tree
-cp_parser_omp_clause_ordered (cp_parser *parser ATTRIBUTE_UNUSED, tree list)
+cp_parser_omp_clause_ordered (cp_parser *parser ATTRIBUTE_UNUSED,
+ tree list, location_t location)
{
tree c;
- check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
+ check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED,
+ "ordered", location);
c = build_omp_clause (OMP_CLAUSE_ORDERED);
OMP_CLAUSE_CHAIN (c) = list;
static | dynamic | guided | runtime | auto */
static tree
-cp_parser_omp_clause_schedule (cp_parser *parser, tree list)
+cp_parser_omp_clause_schedule (cp_parser *parser, tree list, location_t location)
{
tree c, t;
if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
{
+ cp_token *token;
cp_lexer_consume_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
t = cp_parser_assignment_expression (parser, false);
if (t == error_mark_node)
goto resync_fail;
else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
- error ("schedule %<runtime%> does not take "
- "a %<chunk_size%> parameter");
+ error ("%Hschedule %<runtime%> does not take "
+ "a %<chunk_size%> parameter", &token->location);
else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
- error ("schedule %<auto%> does not take "
- "a %<chunk_size%> parameter");
+ error ("%Hschedule %<auto%> does not take "
+ "a %<chunk_size%> parameter", &token->location);
else
OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
else if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "%<,%> or %<)%>"))
goto resync_fail;
- check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
+ check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule", location);
OMP_CLAUSE_CHAIN (c) = list;
return c;
untied */
static tree
-cp_parser_omp_clause_untied (cp_parser *parser ATTRIBUTE_UNUSED, tree list)
+cp_parser_omp_clause_untied (cp_parser *parser ATTRIBUTE_UNUSED,
+ tree list, location_t location)
{
tree c;
- check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
+ check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied", location);
c = build_omp_clause (OMP_CLAUSE_UNTIED);
OMP_CLAUSE_CHAIN (c) = list;
{
tree clauses = NULL;
bool first = true;
+ cp_token *token = NULL;
while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
{
if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
cp_lexer_consume_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
c_kind = cp_parser_omp_clause_name (parser);
first = false;
switch (c_kind)
{
case PRAGMA_OMP_CLAUSE_COLLAPSE:
- clauses = cp_parser_omp_clause_collapse (parser, clauses);
+ clauses = cp_parser_omp_clause_collapse (parser, clauses,
+ token->location);
c_name = "collapse";
break;
case PRAGMA_OMP_CLAUSE_COPYIN:
c_name = "copyprivate";
break;
case PRAGMA_OMP_CLAUSE_DEFAULT:
- clauses = cp_parser_omp_clause_default (parser, clauses);
+ clauses = cp_parser_omp_clause_default (parser, clauses,
+ token->location);
c_name = "default";
break;
case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
c_name = "firstprivate";
break;
case PRAGMA_OMP_CLAUSE_IF:
- clauses = cp_parser_omp_clause_if (parser, clauses);
+ clauses = cp_parser_omp_clause_if (parser, clauses, token->location);
c_name = "if";
break;
case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
c_name = "lastprivate";
break;
case PRAGMA_OMP_CLAUSE_NOWAIT:
- clauses = cp_parser_omp_clause_nowait (parser, clauses);
+ clauses = cp_parser_omp_clause_nowait (parser, clauses, token->location);
c_name = "nowait";
break;
case PRAGMA_OMP_CLAUSE_NUM_THREADS:
- clauses = cp_parser_omp_clause_num_threads (parser, clauses);
+ clauses = cp_parser_omp_clause_num_threads (parser, clauses,
+ token->location);
c_name = "num_threads";
break;
case PRAGMA_OMP_CLAUSE_ORDERED:
- clauses = cp_parser_omp_clause_ordered (parser, clauses);
+ clauses = cp_parser_omp_clause_ordered (parser, clauses,
+ token->location);
c_name = "ordered";
break;
case PRAGMA_OMP_CLAUSE_PRIVATE:
c_name = "reduction";
break;
case PRAGMA_OMP_CLAUSE_SCHEDULE:
- clauses = cp_parser_omp_clause_schedule (parser, clauses);
+ clauses = cp_parser_omp_clause_schedule (parser, clauses,
+ token->location);
c_name = "schedule";
break;
case PRAGMA_OMP_CLAUSE_SHARED:
c_name = "shared";
break;
case PRAGMA_OMP_CLAUSE_UNTIED:
- clauses = cp_parser_omp_clause_untied (parser, clauses);
+ clauses = cp_parser_omp_clause_untied (parser, clauses,
+ token->location);
c_name = "nowait";
break;
default:
/* Remove the invalid clause(s) from the list to avoid
confusing the rest of the compiler. */
clauses = prev;
- error ("%qs is not valid for %qs", c_name, where);
+ error ("%H%qs is not valid for %qs", &token->location, c_name, where);
}
}
saw_error:
cp_lexer_get_preprocessor_token (NULL, first_token);
if (first_token->type != CPP_PRAGMA_EOL)
- error ("junk at end of %<#pragma GCC pch_preprocess%>");
+ error ("%Hjunk at end of %<#pragma GCC pch_preprocess%>",
+ &first_token->location);
}
else
- error ("expected string literal");
+ error ("%Hexpected string literal", &first_token->location);
/* Skip to the end of the pragma. */
while (first_token->type != CPP_PRAGMA_EOL && first_token->type != CPP_EOF)
switch (id)
{
case PRAGMA_GCC_PCH_PREPROCESS:
- error ("%<#pragma GCC pch_preprocess%> must be first");
+ error ("%H%<#pragma GCC pch_preprocess%> must be first",
+ &pragma_tok->location);
break;
case PRAGMA_OMP_BARRIER:
cp_parser_omp_barrier (parser, pragma_tok);
return false;
case pragma_stmt:
- error ("%<#pragma omp barrier%> may only be "
- "used in compound statements");
+ error ("%H%<#pragma omp barrier%> may only be "
+ "used in compound statements", &pragma_tok->location);
break;
default:
goto bad_stmt;
cp_parser_omp_flush (parser, pragma_tok);
return false;
case pragma_stmt:
- error ("%<#pragma omp flush%> may only be "
- "used in compound statements");
+ error ("%H%<#pragma omp flush%> may only be "
+ "used in compound statements", &pragma_tok->location);
break;
default:
goto bad_stmt;
return true;
case PRAGMA_OMP_SECTION:
- error ("%<#pragma omp section%> may only be used in "
- "%<#pragma omp sections%> construct");
+ error ("%H%<#pragma omp section%> may only be used in "
+ "%<#pragma omp sections%> construct", &pragma_tok->location);
break;
default: