C++: add fixit for '>>' template error
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 30 Aug 2016 21:21:42 +0000 (21:21 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 30 Aug 2016 21:21:42 +0000 (21:21 +0000)
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
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/double-greater-than-fixit.C [new file with mode: 0644]

index 7ae6f53f7e48acb8256b66918725bbfbd67d0fd0..c553796d7bf75237c03e95eb249f179d351b6652 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-30  David Malcolm  <dmalcolm@redhat.com>
+
+       * parser.c (cp_parser_enclosed_template_argument_list): Add fix-it
+       hint to ">>" within nested template argument list error.
+
 2016-08-30  David Malcolm  <dmalcolm@redhat.com>
 
        * name-lookup.c (suggest_alternatives_for): Use add_fixit_replace
index 48dbca17bc46de652449181297fbb772d6c8c1f6..ca9f8b9761a5aaf829f81f21e8166078466bd270 100644 (file)
@@ -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;
        }
index ffd44916917aca0ffdd84bf0935d0511cc3e7c8f..6e3b70662d098e123f43b83fe6a8e2d6f94b347f 100644 (file)
@@ -1,3 +1,7 @@
+2016-08-30  David Malcolm  <dmalcolm@redhat.com>
+
+       * g++.dg/template/double-greater-than-fixit.C: New test case.
+
 2016-08-30  Eric Botcazou  <ebotcazou@adacore.com>
 
        * 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 (file)
index 0000000..f0de4ec
--- /dev/null
@@ -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 "" } */