aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2017-06-28 15:41:24 -0400
committerJason Merrill <jason@gcc.gnu.org>2017-06-28 15:41:24 -0400
commitdc3b932e33b703b0163fd6383f26e6c44fe68c6a (patch)
tree34f085f919f4262cf12a16c6e6b69ffc0cb1420a
parent2a4754f59786550a11706d807753c1747968ed01 (diff)
downloadgcc-dc3b932e33b703b0163fd6383f26e6c44fe68c6a.zip
gcc-dc3b932e33b703b0163fd6383f26e6c44fe68c6a.tar.gz
gcc-dc3b932e33b703b0163fd6383f26e6c44fe68c6a.tar.bz2
Make the TEMPLATE_ID_EXPR location a range.
* parser.c (cp_parser_template_id): Use the range location on the TEMPLATE_ID_EXPR. From-SVN: r249751
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/parser.c38
2 files changed, 21 insertions, 20 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 23586d4..7f61172 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
2017-06-28 Jason Merrill <jason@redhat.com>
+ * parser.c (cp_parser_template_id): Use the range location on the
+ TEMPLATE_ID_EXPR.
+
PR c++/81204 - parse error with dependent template-name
* parser.c (cp_parser_lookup_name): Disqualify function templates
after lookup.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index e0a6c8b..246af76 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15522,17 +15522,17 @@ cp_parser_template_id (cp_parser *parser,
/* If the next token corresponds to a template-id, there is no need
to reparse it. */
- next_token = cp_lexer_peek_token (parser->lexer);
- if (next_token->type == CPP_TEMPLATE_ID)
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ if (token->type == CPP_TEMPLATE_ID)
{
cp_lexer_consume_token (parser->lexer);
- return saved_checks_value (next_token->u.tree_check_value);
+ return saved_checks_value (token->u.tree_check_value);
}
/* Avoid performing name lookup if there is no possibility of
finding a template-id. */
- if ((next_token->type != CPP_NAME && next_token->keyword != RID_OPERATOR)
- || (next_token->type == CPP_NAME
+ if ((token->type != CPP_NAME && token->keyword != RID_OPERATOR)
+ || (token->type == CPP_NAME
&& !cp_parser_nth_token_starts_template_argument_list_p
(parser, 2)))
{
@@ -15623,9 +15623,19 @@ cp_parser_template_id (cp_parser *parser,
arguments = cp_parser_enclosed_template_argument_list (parser);
}
+ /* Set the location to be of the form:
+ template-name < template-argument-list [opt] >
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ with caret == start at the start of the template-name,
+ ranging until the closing '>'. */
+ location_t finish_loc
+ = get_finish (cp_lexer_previous_token (parser->lexer)->location);
+ location_t combined_loc
+ = make_location (token->location, token->location, finish_loc);
+
/* Build a representation of the specialization. */
if (identifier_p (templ))
- template_id = build_min_nt_loc (next_token->location,
+ template_id = build_min_nt_loc (combined_loc,
TEMPLATE_ID_EXPR,
templ, arguments);
else if (DECL_TYPE_TEMPLATE_P (templ)
@@ -15652,7 +15662,7 @@ cp_parser_template_id (cp_parser *parser,
{
template_id = lookup_template_variable (templ, arguments);
if (TREE_CODE (template_id) == TEMPLATE_ID_EXPR)
- SET_EXPR_LOCATION (template_id, next_token->location);
+ SET_EXPR_LOCATION (template_id, combined_loc);
}
else
{
@@ -15664,7 +15674,7 @@ cp_parser_template_id (cp_parser *parser,
template_id = lookup_template_function (templ, arguments);
if (TREE_CODE (template_id) == TEMPLATE_ID_EXPR)
- SET_EXPR_LOCATION (template_id, next_token->location);
+ SET_EXPR_LOCATION (template_id, combined_loc);
}
/* If parsing tentatively, replace the sequence of tokens that makes
@@ -15680,20 +15690,8 @@ cp_parser_template_id (cp_parser *parser,
&& cp_parser_parsing_tentatively (parser)
&& parser->in_declarator_p))
{
- cp_token *token = cp_lexer_token_at (parser->lexer, start_of_id);
-
/* Reset the contents of the START_OF_ID token. */
token->type = CPP_TEMPLATE_ID;
-
- /* Update the location to be of the form:
- template-name < template-argument-list [opt] >
- ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- with caret == start at the start of the template-name,
- ranging until the closing '>'. */
- location_t finish_loc
- = get_finish (cp_lexer_previous_token (parser->lexer)->location);
- location_t combined_loc
- = make_location (token->location, token->location, finish_loc);
token->location = combined_loc;
/* We must mark the lookup as kept, so we don't throw it away on