This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This patch implements fix-it hints. See https://gcc.gnu.org/PR62314 When the caret line is active (which is the default), this adds an additional source-line indicating how to fix the code: gcc/testsuite/g++.dg/template/crash83.C:5:21: error: an explicit specialization must be preceded by 'template <>' template<typename = class A<0>: > struct B {}; // { dg-error "explicit specialization|expected" } ^ template<> When the caret line is disabled with -fno-diagnostics-show-caret, the fix-it hint is printed as: gcc/testsuite/g++.dg/template/crash83.C:5:21: error: an explicit specialization must be preceded by 'template <>' gcc/testsuite/g++.dg/template/crash83.C:5:21: fixit: template<> The latter form may allow an IDE (such as emacs) to automatically apply the fix. Currently, fix-it hints are limited to insertions at one single location, whereas Clang allows insertions, deletions, and replacements at arbitrary location ranges. Opinions? Is the proposed interface/implementation acceptable? Any other diagnostics that could use a fix-it hint? In principle, we should only give them when we are sure that the proposed fix will fix the error or silence a warning. For example, the C++ parser often says 'x' expected before 'y' but adding x before y rarely fixes anything. gcc/ChangeLog: 2014-08-31 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/62314 * diagnostic.def (DK_FIXIT): New. * diagnostic.c (adjust_column): New. (adjust_line): Factor out adjust_column. (get_source_line_and_column): New. (diagnostic_show_locus): Call get_source_line_and_column. (diagnostic_action_after_output): Ignore DK_FIXIT. (fixit_hint): New. * diagnostic-core.h (fixit_hint): Declare. gcc/cp/ChangeLog: 2014-08-31 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/62314 * parser.c (cp_parser_diagnose_invalid_type_name): Call fixit_hint. (cp_parser_expression_statement): Likewise. (cp_parser_class_head): Likewise. Update location. gcc/testsuite/ChangeLog: 2014-08-31 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/62314 * g++.old-deja/g++.oliva/typename1.C: Handle fixit hint. * g++.old-deja/g++.oliva/typename2.C: Likewise. * g++.old-deja/g++.other/typename1.C: Likewise. * g++.old-deja/g++.pt/typename6.C: Likewise. * g++.old-deja/g++.pt/typename3.C: Likewise. * g++.old-deja/g++.pt/typename4.C: Likewise. * g++.dg/parse/error36.C: Likewise. * g++.dg/parse/typedef2.C: Likewise. * g++.dg/template/error6.C: Likewise. * g++.dg/template/dependent-name5.C: Likewise. * g++.dg/template/crash83.C: Likewise. * g++.dg/template/typename3.C: Likewise.
Attachment:
fixit-hints.diff
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |