* [PATCH] C++: add fixit for '>>' template error
@ 2016-08-30 14:14 David Malcolm
2016-08-30 21:13 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: David Malcolm @ 2016-08-30 14:14 UTC (permalink / raw)
To: gcc-patches; +Cc: David Malcolm
This patch adds fix-it hints to our warning for >>
within a nested template argument list (for -std=c++98).
For example:
double-greater-than-fixit.C:5:12: error: â>>â should be â> >â within a nested template argument list
foo<foo<int>> i;
^~
> >
In conjunction with the not-yet-in-trunk -fdiagnostics-generate-patch,
this can generate patches like this:
--- double-greater-than-fixit.C
+++ double-greater-than-fixit.C
@@ -4,3 +4,3 @@
-foo<foo<int>> i;
+foo<foo<int> > i;
Successfully bootstrapped®rtested on x86_64-pc-linux-gnu.
OK for trunk?
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.
---
gcc/cp/parser.c | 6 ++++--
gcc/testsuite/g++.dg/template/double-greater-than-fixit.C | 10 ++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/double-greater-than-fixit.C
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 48dbca1..ca9f8b9 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/g++.dg/template/double-greater-than-fixit.C b/gcc/testsuite/g++.dg/template/double-greater-than-fixit.C
new file mode 100644
index 0000000..f0de4ec
--- /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 <typename T>
+struct foo {};
+
+foo<foo<int>> i; // { dg-error "12: .>>. should be .> >. within a nested template argument list" }
+/* { dg-begin-multiline-output "" }
+ foo<foo<int>> i;
+ ^~
+ > >
+ { dg-end-multiline-output "" } */
--
1.8.5.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] C++: add fixit for '>>' template error
2016-08-30 14:14 [PATCH] C++: add fixit for '>>' template error David Malcolm
@ 2016-08-30 21:13 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-08-30 21:13 UTC (permalink / raw)
To: David Malcolm; +Cc: gcc-patches List
OK.
On Tue, Aug 30, 2016 at 10:43 AM, David Malcolm <dmalcolm@redhat.com> wrote:
> This patch adds fix-it hints to our warning for >>
> within a nested template argument list (for -std=c++98).
>
> For example:
>
> double-greater-than-fixit.C:5:12: error: ‘>>’ should be ‘> >’ within a nested template argument list
> foo<foo<int>> i;
> ^~
> > >
>
> In conjunction with the not-yet-in-trunk -fdiagnostics-generate-patch,
> this can generate patches like this:
>
> --- double-greater-than-fixit.C
> +++ double-greater-than-fixit.C
> @@ -4,3 +4,3 @@
>
> -foo<foo<int>> i;
> +foo<foo<int> > i;
>
> Successfully bootstrapped®rtested on x86_64-pc-linux-gnu.
>
> OK for trunk?
>
> 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.
> ---
> gcc/cp/parser.c | 6 ++++--
> gcc/testsuite/g++.dg/template/double-greater-than-fixit.C | 10 ++++++++++
> 2 files changed, 14 insertions(+), 2 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/template/double-greater-than-fixit.C
>
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 48dbca1..ca9f8b9 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/g++.dg/template/double-greater-than-fixit.C b/gcc/testsuite/g++.dg/template/double-greater-than-fixit.C
> new file mode 100644
> index 0000000..f0de4ec
> --- /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 <typename T>
> +struct foo {};
> +
> +foo<foo<int>> i; // { dg-error "12: .>>. should be .> >. within a nested template argument list" }
> +/* { dg-begin-multiline-output "" }
> + foo<foo<int>> i;
> + ^~
> + > >
> + { dg-end-multiline-output "" } */
> --
> 1.8.5.3
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-30 21:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30 14:14 [PATCH] C++: add fixit for '>>' template error David Malcolm
2016-08-30 21:13 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).