Commit 84ca3893 by David Malcolm Committed by David Malcolm

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
parent 20d0bfce
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> 2016-07-04 Jan Beulich <jbeulich@suse.com>
* lang-specs.h ("@c++-header"): Conditionalize "-o". * lang-specs.h ("@c++-header"): Conditionalize "-o".
......
...@@ -21450,17 +21450,30 @@ cp_parser_class_specifier_1 (cp_parser* parser) ...@@ -21450,17 +21450,30 @@ cp_parser_class_specifier_1 (cp_parser* parser)
closing brace. */ closing brace. */
if (closing_brace && TYPE_P (type) && want_semicolon) if (closing_brace && TYPE_P (type) && want_semicolon)
{ {
/* Locate the closing brace. */
cp_token_position prev cp_token_position prev
= cp_lexer_previous_token_position (parser->lexer); = cp_lexer_previous_token_position (parser->lexer);
cp_token *prev_token = cp_lexer_token_at (parser->lexer, prev); cp_token *prev_token = cp_lexer_token_at (parser->lexer, prev);
location_t loc = prev_token->location; 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)) 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) 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) else if (TREE_CODE (type) == UNION_TYPE)
error_at (loc, "expected %<;%> after union definition"); error_at_rich_loc (&richloc,
"expected %<;%> after union definition");
else else
gcc_unreachable (); gcc_unreachable ();
2016-07-05 David Malcolm <dmalcolm@redhat.com>
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.
2016-07-05 Alessandro Fanfarillo <fanfarillo.gcc@gmail.com> 2016-07-05 Alessandro Fanfarillo <fanfarillo.gcc@gmail.com>
* gfortran.dg/coarray_stat_function.f90: New test. * gfortran.dg/coarray_stat_function.f90: New test.
......
...@@ -13,7 +13,7 @@ class Foo { int foo() return 0; } }; ...@@ -13,7 +13,7 @@ class Foo { int foo() return 0; } };
// need make cp_parser_error() report more accurate column numbers. // need make cp_parser_error() report more accurate column numbers.
// { dg-error "30:expected '\{' at end of input" "brace" { target *-*-* } 4 } // { dg-error "30:expected '\{' at end of input" "brace" { target *-*-* } 4 }
// { dg-error "33:expected ';' after class definition" "semicolon" {target *-*-* } 4 } // { dg-error "34:expected ';' after class definition" "semicolon" {target *-*-* } 4 }
// { dg-error "35:expected declaration before '\}' token" "declaration" {target *-*-* } 4 } // { dg-error "35:expected declaration before '\}' token" "declaration" {target *-*-* } 4 }
// { dg-options "-fdiagnostics-show-caret" }
template<class T>
class a {} // { dg-error "11: expected .;. after class definition" }
class temp {};
a<temp> b;
struct b {
} // { dg-error "2: expected .;. after struct definition" }
/* Verify that we emit fixit hints. */
/* { dg-begin-multiline-output "" }
class a {}
^
;
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
}
^
;
{ dg-end-multiline-output "" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment