Commit bdd03984 by David Malcolm Committed by David Malcolm

C++: fix-it hint for missing "typename" (PR c++/63392)

This patch adds a fix-it hint to missing "typename" errors in the C++
frontend, suggesting the insertion of "typename ".

This addresses part of PR c++/63392; however it does not improve the
error-recovery for such cases.

gcc/cp/ChangeLog:
	PR c++/63392
	* parser.c (cp_parser_diagnose_invalid_type_name): Add fix-it
	hint.

gcc/testsuite/ChangeLog:
	PR c++/63392
	* g++.dg/diagnostic/missing-typename.C: New test.

From-SVN: r263899
parent 6a2a6928
2018-08-27 David Malcolm <dmalcolm@redhat.com>
PR c++/63392
* parser.c (cp_parser_diagnose_invalid_type_name): Add fix-it
hint.
2018-08-27 Jakub Jelinek <jakub@redhat.com> 2018-08-27 Jakub Jelinek <jakub@redhat.com>
PR c++/86993 PR c++/86993
......
...@@ -3405,8 +3405,10 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id, ...@@ -3405,8 +3405,10 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
else if (TYPE_P (parser->scope) else if (TYPE_P (parser->scope)
&& dependent_scope_p (parser->scope)) && dependent_scope_p (parser->scope))
{ {
gcc_rich_location richloc (location);
richloc.add_fixit_insert_before ("typename ");
if (TREE_CODE (parser->scope) == TYPENAME_TYPE) if (TREE_CODE (parser->scope) == TYPENAME_TYPE)
error_at (location, error_at (&richloc,
"need %<typename%> before %<%T::%D::%E%> because " "need %<typename%> before %<%T::%D::%E%> because "
"%<%T::%D%> is a dependent scope", "%<%T::%D%> is a dependent scope",
TYPE_CONTEXT (parser->scope), TYPE_CONTEXT (parser->scope),
...@@ -3415,7 +3417,7 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id, ...@@ -3415,7 +3417,7 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
TYPE_CONTEXT (parser->scope), TYPE_CONTEXT (parser->scope),
TYPENAME_TYPE_FULLNAME (parser->scope)); TYPENAME_TYPE_FULLNAME (parser->scope));
else else
error_at (location, "need %<typename%> before %<%T::%E%> because " error_at (&richloc, "need %<typename%> before %<%T::%E%> because "
"%qT is a dependent scope", "%qT is a dependent scope",
parser->scope, id, parser->scope); parser->scope, id, parser->scope);
} }
2018-08-27 David Malcolm <dmalcolm@redhat.com>
PR c++/63392
* g++.dg/diagnostic/missing-typename.C: New test.
2018-08-27 Jeff Law <law@redhat.com> 2018-08-27 Jeff Law <law@redhat.com>
* gcc.c-torture/compile/dse.c: New test. * gcc.c-torture/compile/dse.c: New test.
......
// fix-it hint for missing "typename" (PR c++/63392)
// { dg-options "-fdiagnostics-show-caret" }
template<typename T>
class test_1 {
T::type x; // { dg-error "need 'typename' before 'T::type' because 'T' is a dependent scope" }
/* { dg-begin-multiline-output "" }
T::type x;
^
typename
{ 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