From 71b308914e31765f2110e6692685e0842c317bed Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 30 Aug 2016 21:21:42 +0000 Subject: [PATCH] C++: add fixit for '>>' template error gcc/cp/ChangeLog: * parser.c (cp_parser_enclosed_template_argument_list): Add fix-it hint to ">>" within nested template argument list error. gcc/testsuite/ChangeLog: * g++.dg/template/double-greater-than-fixit.C: New test case. From-SVN: r239873 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 6 ++++-- gcc/testsuite/ChangeLog | 4 ++++ .../g++.dg/template/double-greater-than-fixit.C | 10 ++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/double-greater-than-fixit.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7ae6f53f7e4..c553796d7bf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-08-30 David Malcolm + + * parser.c (cp_parser_enclosed_template_argument_list): Add fix-it + hint to ">>" within nested template argument list error. + 2016-08-30 David Malcolm * name-lookup.c (suggest_alternatives_for): Use add_fixit_replace diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 48dbca17bc4..ca9f8b9761a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -26342,8 +26342,10 @@ cp_parser_enclosed_template_argument_list (cp_parser* parser) global source location is still on the token before the '>>', so we need to say explicitly where we want it. */ cp_token *token = cp_lexer_peek_token (parser->lexer); - error_at (token->location, "%<>>%> should be %<> >%> " - "within a nested template argument list"); + gcc_rich_location richloc (token->location); + richloc.add_fixit_replace ("> >"); + error_at_rich_loc (&richloc, "%<>>%> should be %<> >%> " + "within a nested template argument list"); token->type = CPP_GREATER; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ffd44916917..6e3b70662d0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-08-30 David Malcolm + + * g++.dg/template/double-greater-than-fixit.C: New test case. + 2016-08-30 Eric Botcazou * gnat.dg/opt57.ad[sb]: New test. diff --git a/gcc/testsuite/g++.dg/template/double-greater-than-fixit.C b/gcc/testsuite/g++.dg/template/double-greater-than-fixit.C new file mode 100644 index 00000000000..f0de4ec35b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/double-greater-than-fixit.C @@ -0,0 +1,10 @@ +/* { dg-options "-fdiagnostics-show-caret -std=c++98" } */ +template +struct foo {}; + +foo> i; // { dg-error "12: .>>. should be .> >. within a nested template argument list" } +/* { dg-begin-multiline-output "" } + foo> i; + ^~ + > > + { dg-end-multiline-output "" } */ -- 2.30.2