aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-07-05 15:50:54 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-07-05 15:50:54 +0000
commit84ca38932bd55f3fc058f4d17c46d132a3745042 (patch)
tree9140a8ba92a6650daa38dd111c0813c0b04dadc7 /gcc/cp
parent20d0bfcefd6caf09c23113732edd98241a46af56 (diff)
downloadgcc-84ca38932bd55f3fc058f4d17c46d132a3745042.zip
gcc-84ca38932bd55f3fc058f4d17c46d132a3745042.tar.gz
gcc-84ca38932bd55f3fc058f4d17c46d132a3745042.tar.bz2
PR c++/62314: add fixit hint for "expected ';' after class definition"
gcc/cp/ChangeLog: PR c++/62314 * parser.c (cp_parser_class_specifier_1): When reporting missing semicolons, use a fixit-hint to suggest insertion of a semicolon immediately after the closing brace, offsetting the reported column accordingly. gcc/testsuite/ChangeLog: PR c++/62314 * gcc/testsuite/g++.dg/parse/error5.C: Update column number of missing semicolon error. * g++.dg/pr62314-2.C: New test case. From-SVN: r238008
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/parser.c19
2 files changed, 24 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7da1c55..c129b5f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2016-07-05 David Malcolm <dmalcolm@redhat.com>
+
+ PR c++/62314
+ * parser.c (cp_parser_class_specifier_1): When reporting
+ missing semicolons, use a fixit-hint to suggest insertion
+ of a semicolon immediately after the closing brace,
+ offsetting the reported column accordingly.
+
2016-07-04 Jan Beulich <jbeulich@suse.com>
* lang-specs.h ("@c++-header"): Conditionalize "-o".
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3e8270e..ef35aa9 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -21450,17 +21450,30 @@ cp_parser_class_specifier_1 (cp_parser* parser)
closing brace. */
if (closing_brace && TYPE_P (type) && want_semicolon)
{
+ /* Locate the closing brace. */
cp_token_position prev
= cp_lexer_previous_token_position (parser->lexer);
cp_token *prev_token = cp_lexer_token_at (parser->lexer, prev);
location_t loc = prev_token->location;
+ /* We want to suggest insertion of a ';' immediately *after* the
+ closing brace, so, if we can, offset the location by 1 column. */
+ location_t next_loc = loc;
+ if (!linemap_location_from_macro_expansion_p (line_table, loc))
+ next_loc = linemap_position_for_loc_and_offset (line_table, loc, 1);
+
+ rich_location richloc (line_table, next_loc);
+ richloc.add_fixit_insert (next_loc, ";");
+
if (CLASSTYPE_DECLARED_CLASS (type))
- error_at (loc, "expected %<;%> after class definition");
+ error_at_rich_loc (&richloc,
+ "expected %<;%> after class definition");
else if (TREE_CODE (type) == RECORD_TYPE)
- error_at (loc, "expected %<;%> after struct definition");
+ error_at_rich_loc (&richloc,
+ "expected %<;%> after struct definition");
else if (TREE_CODE (type) == UNION_TYPE)
- error_at (loc, "expected %<;%> after union definition");
+ error_at_rich_loc (&richloc,
+ "expected %<;%> after union definition");
else
gcc_unreachable ();