In the C++ FE, after emitting various errors about unrecognized names, the parser can call suggest_alternatives_for and/or suggest_alternative_in_explicit_scope. These can issue zero or more suggestions for the unrecognized name, or various other "note" diagnostics suggesting how to fix the problem. For example, currently g++ emits: t.cc:12:3: error: 'gtk_widget_showall' was not declared in this scope 12 | gtk_widget_showall (w); | ^~~~~~~~~~~~~~~~~~ t.cc:12:3: note: suggested alternative: 'gtk_widget_show_all' 12 | gtk_widget_showall (w); | ^~~~~~~~~~~~~~~~~~ | gtk_widget_show_all This patch consolidates the common case when there is a single candidate, so that the error can issue a fix-it hint directly. This simplifies the above to: t.cc:12:3: error: 'gtk_widget_showall' was not declared in this scope; did you mean 'gtk_widget_show_all'? 12 | gtk_widget_showall (w); | ^~~~~~~~~~~~~~~~~~ | gtk_widget_show_all omitting the second "note" diagnostic. Doing so requires changing the above "suggest_" functions so that rather than being called after "error" and emitting a note directly, they are called before the "error", and return a name_hint, which can contain a suggestion and/or a deferred diagnostic. The "single candidate" case is handled via a suggestion, and the "multiple candidates" case via a new subclass of deferred_diagnostic. There was some complication due to the fact that we don't always have enough location information to issue a fix-it hint. Specifically, for the case in qualified_name_lookup_error, the location is that of the name, but the location of the qualifier prefix isn't reliably available. For some hints, e.g. spell-corrections, the replacement is of the name, and for others, e.g. parent namespaces, it's for the qualified name. The patch addresses this by splitting this case out into a new "suggest_alternatives_in_other_namespaces" function, for which fix-it hints aren't issued. Another complication is that of emitting a note when --param cxx-max-namespaces-for-diagnostic-help is reached. The patch emulates the existing behavior by emitting the note from a deferred_diagnostic. This potentially needs to co-exist with another deferred_diagnostic, so it works as a decorator around any other such deferred_diagnostic. Doing so requires slightly extending class name_hint. On adding test coverage for the various cases, I discovered that after emitting a "FOO is not a namespace-name" error, we also emit a "expected namespace-name before" error. The patch removes this second error for the case where it's redundant, simplifying this case from e.g.: spellcheck-ns.C:10:24: error: 'inner_ms' is not a namespace-name 10 | using namespace outer::inner_ms; | ^~~~~~~~ spellcheck-ns.C:10:24: note: suggested alternative: 'inner_ns' 10 | using namespace outer::inner_ms; | ^~~~~~~~ | inner_ns spellcheck-ns.C:10:32: error: expected namespace-name before ';' token 10 | using namespace outer::inner_ms; | ^ to: spellcheck-ns.C:10:24: error: 'inner_ms' is not a namespace-name; did you mean 'inner_ns'? 10 | using namespace outer::inner_ms; | ^~~~~~~~ | inner_ns include/ChangeLog: * unique-ptr.h (gnu::move): Generalize so it applies to all lvalue references, rather than just to unique_ptr values. gcc/c-family/ChangeLog: * name-hint.h (name_hint::take_deferred): New member function. gcc/c/ChangeLog: * c-decl.c (implicit_decl_warning): Update "is there a suggestion" logic for change to name_hint::operator bool. (undeclared_variable): Likewise. * c-parser.c (c_parser_declaration_or_fndef): Likewise. (c_parser_parameter_declaration): Likewise. gcc/cp/ChangeLog: * cp-name-hint.h: New file. * cp-tree.h (expr_to_string): New decl. (suggest_alternatives_for): Move to cp-name-hint.h, changing return type from bool to name_hint. (suggest_alternative_in_explicit_scope): Likewise. * error.c: Define INCLUDE_UNIQUE_PTR. Include "cp-name-hint.h". (expr_to_string): Make non-static. (qualified_name_lookup_error): For the non-"::" case, take responsibity for issuing any suggestion from suggest_alternative_in_explicit_scope, as it changes from returning a bool to returning a name_hint. Replace fallback call to suggest_alternatives_for to a call to suggest_alternatives_in_other_namespaces, capturing the fact that we don't have enough location information to issue a fix-it hint for this case. Update the error to support emitting a fix-it hint where appropriate. For the "::" case, take responsibility for issuing any suggestion from suggest_alternatives_for, supporting emitting a fix-it hint. * lex.c: Define INCLUDE_UNIQUE_PTR. Include "gcc-rich-location.h" and "cp-name-hint.h". (unqualified_name_lookup_error): Take responsibility for issuing any suggestion from suggest_alternatives_for, supporting emitting a fix-it hint. * name-lookup.c (class namespace_limit_reached): New subclass of deferred_diagnostic. (class show_candidate_location): Likewise. (class suggest_alternatives): Likewise. (class namespace_hints): New class. (suggest_alternatives_for): Convert return type from bool to name_hint, replacing all direct diagnostic emission by setting suggestions on the return value, or creating deferred diagnostics. Specifically, split out initial traversal of namespaces into namespace_hints' ctor, and maybe_decorate_with_limit, and move the rest of the implementation to namespace_hints::convert_candidates_to_name_hint and suggest_alternatives_for_1. (namespace_hints::namespace_hints): New ctor, adapted from suggest_alternatives_for's initial namespace traversal, storing location and name, and converting locals "candidates", "limited" and "limit" into members. (namespace_hints::convert_candidates_to_name_hint): New member function. (namespace_hints::maybe_decorate_with_limit): New member function. (suggest_alternatives_for_1): New function, based on second half of old implementation of suggest_alternatives_for, converting from immediate emission of suggestions to using name_hint. (suggest_alternatives_in_other_namespaces): New function. (maybe_suggest_missing_std_header): Convert from immediate emission of suggestions to using name_hint, moving emission implementation to... (class missing_std_header): New subclass of deferred_diagnostic. (maybe_suggest_missing_header): Convert return type from bool to name_hint. (suggest_alternative_in_explicit_scope): Convert from immediate emission of suggestions to using name_hint. * parser.c: Replace include of "c-family/name-hint.h" with "cp-name-hint.h". (cp_parser_diagnose_invalid_type_name): Update "is there a suggestion" logic for change to name_hint::operator bool. Take responsibility for emitting fix-it hints from suggest_alternative_in_explicit_scope. (cp_parser_namespace_name): Take responsibility for emitting fix-it hints from suggest_alternative_in_explicit_scope. Don't emit the "expected namespace-name" error if we've already emitted an "is not a namespace-name" error. gcc/testsuite/ChangeLog: * c-c++-common/spellcheck-reserved.c: Update expected output for C++ for merger of "did you mean" suggestions into the error message. * g++.dg/ext/builtin3.C: Update expected output for merger of "did you mean" suggestion into the error. * g++.dg/lookup/error1.C: Likewise. * g++.dg/lookup/pr77549.C: Likewise. * g++.dg/lookup/pr80913.C: Likewise. * g++.dg/lookup/suggestions1.C: Likewise. * g++.dg/lookup/suggestions2.C: New test. * g++.dg/overload/koenig1.C: Update expected output as above. * g++.dg/spellcheck-identifiers-2.C: Likewise. * g++.dg/spellcheck-identifiers.C: Likewise. * g++.dg/spellcheck-ns.C: New test. * g++.dg/spellcheck-pr77829.C: Update expected output as above. * g++.dg/spellcheck-pr78656.C: Likewise. * g++.dg/spellcheck-pr79298.C: Likewise, adding -fdiagnostics-show-caret to options. * g++.dg/spellcheck-pr80177.C: Likewise. * g++.dg/spellcheck-single-vs-multiple.C: New test. * g++.dg/spellcheck-typenames.C: Update expected output as above. * g++.dg/template/static10.C: Likewise. * g++.old-deja/g++.mike/ns5.C: Likewise. * g++.old-deja/g++.mike/ns7.C: Likewise. * g++.old-deja/g++.ns/koenig5.C: Likewise. * g++.old-deja/g++.other/lineno5.C: Likewise. libstdc++-v3/ChangeLog: * testsuite/17_intro/using_namespace_std_exp_neg.cc: Remove "expected namespace-name before" error. * testsuite/17_intro/using_namespace_std_tr1_neg.cc: Likewise. From-SVN: r265610
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
align1.C | Loading commit data... | |
align2.C | Loading commit data... | |
ambig1.C | Loading commit data... | |
asm1.C | Loading commit data... | |
asm2.C | Loading commit data... | |
bool1.C | Loading commit data... | |
bool2.C | Loading commit data... | |
bool4.C | Loading commit data... | |
conv1.C | Loading commit data... | |
debug1.C | Loading commit data... | |
dyncast1.C | Loading commit data... | |
dyncast2.C | Loading commit data... | |
dyncast3.C | Loading commit data... | |
dyncast4.C | Loading commit data... | |
dyncast5.C | Loading commit data... | |
dyncast6.C | Loading commit data... | |
dyncast7.C | Loading commit data... | |
dyncast8.C | Loading commit data... | |
dyncast9.C | Loading commit data... | |
eh1.C | Loading commit data... | |
eh10.C | Loading commit data... | |
eh11.C | Loading commit data... | |
eh12.C | Loading commit data... | |
eh13.C | Loading commit data... | |
eh14.C | Loading commit data... | |
eh15.C | Loading commit data... | |
eh16.C | Loading commit data... | |
eh17.C | Loading commit data... | |
eh18.C | Loading commit data... | |
eh19.C | Loading commit data... | |
eh2.C | Loading commit data... | |
eh20.C | Loading commit data... | |
eh21.C | Loading commit data... | |
eh23.C | Loading commit data... | |
eh24.C | Loading commit data... | |
eh25.C | Loading commit data... | |
eh26.C | Loading commit data... | |
eh27.C | Loading commit data... | |
eh28.C | Loading commit data... | |
eh29.C | Loading commit data... | |
eh3.C | Loading commit data... | |
eh30.C | Loading commit data... | |
eh31.C | Loading commit data... | |
eh32.C | Loading commit data... | |
eh33.C | Loading commit data... | |
eh34.C | Loading commit data... | |
eh35.C | Loading commit data... | |
eh36.C | Loading commit data... | |
eh37.C | Loading commit data... | |
eh38.C | Loading commit data... | |
eh39.C | Loading commit data... | |
eh4.C | Loading commit data... | |
eh40.C | Loading commit data... | |
eh41.C | Loading commit data... | |
eh42.C | Loading commit data... | |
eh44.C | Loading commit data... | |
eh45.C | Loading commit data... | |
eh46.C | Loading commit data... | |
eh47.C | Loading commit data... | |
eh48.C | Loading commit data... | |
eh49.C | Loading commit data... | |
eh5.C | Loading commit data... | |
eh50.C | Loading commit data... | |
eh51.C | Loading commit data... | |
eh52.C | Loading commit data... | |
eh53.C | Loading commit data... | |
eh54.C | Loading commit data... | |
eh55.C | Loading commit data... | |
eh56.C | Loading commit data... | |
eh57.C | Loading commit data... | |
eh58.C | Loading commit data... | |
eh59.C | Loading commit data... | |
eh6.C | Loading commit data... | |
eh7.C | Loading commit data... | |
eh8.C | Loading commit data... | |
eh9.C | Loading commit data... | |
enum1.C | Loading commit data... | |
err1.C | Loading commit data... | |
err2.C | Loading commit data... | |
err3.C | Loading commit data... | |
explicit1.C | Loading commit data... | |
explicit2.C | Loading commit data... | |
for1.C | Loading commit data... | |
for2.C | Loading commit data... | |
for3.C | Loading commit data... | |
fresco1.C | Loading commit data... | |
hog1.C | Loading commit data... | |
init1.C | Loading commit data... | |
init2.C | Loading commit data... | |
leak1.C | Loading commit data... | |
mangle1.C | Loading commit data... | |
mangle2.C | Loading commit data... | |
mangle3.C | Loading commit data... | |
mi1.C | Loading commit data... | |
mi2.C | Loading commit data... | |
misc1.C | Loading commit data... | |
misc11.C | Loading commit data... | |
misc12.C | Loading commit data... | |
misc13.C | Loading commit data... | |
misc14.C | Loading commit data... | |
misc2.C | Loading commit data... | |
misc3.C | Loading commit data... | |
misc5.C | Loading commit data... | |
misc6.C | Loading commit data... | |
misc7.C | Loading commit data... | |
misc8.C | Loading commit data... | |
misc9.C | Loading commit data... | |
net1.C | Loading commit data... | |
net10.C | Loading commit data... | |
net11.C | Loading commit data... | |
net12.C | Loading commit data... | |
net13.C | Loading commit data... | |
net14.C | Loading commit data... | |
net15.C | Loading commit data... | |
net16.C | Loading commit data... | |
net17.C | Loading commit data... | |
net18.C | Loading commit data... | |
net19.C | Loading commit data... | |
net2.C | Loading commit data... | |
net20.C | Loading commit data... | |
net21.C | Loading commit data... | |
net22.C | Loading commit data... | |
net23.C | Loading commit data... | |
net24.C | Loading commit data... | |
net25.C | Loading commit data... | |
net26.C | Loading commit data... | |
net27.C | Loading commit data... | |
net28.C | Loading commit data... | |
net29.C | Loading commit data... | |
net3.C | Loading commit data... | |
net30.C | Loading commit data... | |
net31.C | Loading commit data... | |
net32.C | Loading commit data... | |
net34.C | Loading commit data... | |
net35.C | Loading commit data... | |
net36.C | Loading commit data... | |
net37.C | Loading commit data... | |
net38.C | Loading commit data... | |
net39.C | Loading commit data... | |
net4.C | Loading commit data... | |
net40.C | Loading commit data... | |
net41.C | Loading commit data... | |
net42.C | Loading commit data... | |
net44.C | Loading commit data... | |
net45.C | Loading commit data... | |
net46.C | Loading commit data... | |
net47.C | Loading commit data... | |
net48.C | Loading commit data... | |
net6.C | Loading commit data... | |
net7.C | Loading commit data... | |
net8.C | Loading commit data... | |
net9.C | Loading commit data... | |
ns1.C | Loading commit data... | |
ns10.C | Loading commit data... | |
ns11.C | Loading commit data... | |
ns12.C | Loading commit data... | |
ns13.C | Loading commit data... | |
ns14.C | Loading commit data... | |
ns15.C | Loading commit data... | |
ns2.C | Loading commit data... | |
ns3.C | Loading commit data... | |
ns4.C | Loading commit data... | |
ns5.C | Loading commit data... | |
ns6.C | Loading commit data... | |
ns7.C | Loading commit data... | |
ns9.C | Loading commit data... | |
offset1.C | Loading commit data... | |
opr-as1.C | Loading commit data... | |
opr-dot1.C | Loading commit data... | |
p10148.C | Loading commit data... | |
p10247.C | Loading commit data... | |
p10416.C | Loading commit data... | |
p10511.C | Loading commit data... | |
p10769b.C | Loading commit data... | |
p10849a.C | Loading commit data... | |
p10951.C | Loading commit data... | |
p11012.C | Loading commit data... | |
p11110.C | Loading commit data... | |
p11142.C | Loading commit data... | |
p11144.C | Loading commit data... | |
p11482.C | Loading commit data... | |
p11667.C | Loading commit data... | |
p12306.C | Loading commit data... | |
p12306a.C | Loading commit data... | |
p1248.C | Loading commit data... | |
p1567.C | Loading commit data... | |
p16146.C | Loading commit data... | |
p1862.C | Loading commit data... | |
p1989.C | Loading commit data... | |
p2394.C | Loading commit data... | |
p2431.C | Loading commit data... | |
p2573.C | Loading commit data... | |
p2736.C | Loading commit data... | |
p2746.C | Loading commit data... | |
p2793.C | Loading commit data... | |
p2806.C | Loading commit data... | |
p2846.C | Loading commit data... | |
p2846a.C | Loading commit data... | |
p2846b.C | Loading commit data... | |
p2855.C | Loading commit data... | |
p2960.C | Loading commit data... | |
p3041.C | Loading commit data... | |
p3060c.C | Loading commit data... | |
p3060d.C | Loading commit data... | |
p3068.C | Loading commit data... | |
p3070.C | Loading commit data... | |
p3139.C | Loading commit data... | |
p3524a.C | Loading commit data... | |
p3524b.C | Loading commit data... | |
p3524c.C | Loading commit data... | |
p3538a.C | Loading commit data... | |
p3538b.C | Loading commit data... | |
p3570.C | Loading commit data... | |
p3579.C | Loading commit data... | |
p3708.C | Loading commit data... | |
p3708a.C | Loading commit data... | |
p3708b.C | Loading commit data... | |
p3764.C | Loading commit data... | |
p3836.C | Loading commit data... | |
p4068.C | Loading commit data... | |
p4104.C | Loading commit data... | |
p4173.C | Loading commit data... | |
p418.C | Loading commit data... | |
p4238.C | Loading commit data... | |
p4246.C | Loading commit data... | |
p4263.C | Loading commit data... | |
p438.C | Loading commit data... | |
p4484.C | Loading commit data... | |
p4511.C | Loading commit data... | |
p4619.C | Loading commit data... | |
p4623.C | Loading commit data... | |
p4667.C | Loading commit data... | |
p4671.C | Loading commit data... | |
p4677.C | Loading commit data... | |
p4693.C | Loading commit data... | |
p4736a.C | Loading commit data... | |
p4736b.C | Loading commit data... | |
p4736c.C | Loading commit data... | |
p4750.C | Loading commit data... | |
p5469.C | Loading commit data... | |
p5469a.C | Loading commit data... | |
p5571.C | Loading commit data... | |
p5611.C | Loading commit data... | |
p5673.C | Loading commit data... | |
p5718.C | Loading commit data... | |
p5793.C | Loading commit data... | |
p5840.C | Loading commit data... | |
p5958.C | Loading commit data... | |
p6004.C | Loading commit data... | |
p6058.C | Loading commit data... | |
p6149.C | Loading commit data... | |
p6311.C | Loading commit data... | |
p646.C | Loading commit data... | |
p6578.C | Loading commit data... | |
p658.C | Loading commit data... | |
p6610a.C | Loading commit data... | |
p6610b.C | Loading commit data... | |
p6611.C | Loading commit data... | |
p6746.C | Loading commit data... | |
p6901.C | Loading commit data... | |
p6927.C | Loading commit data... | |
p700.C | Loading commit data... | |
p701.C | Loading commit data... | |
p710.C | Loading commit data... | |
p7180.C | Loading commit data... | |
p7476.C | Loading commit data... | |
p755.C | Loading commit data... | |
p755a.C | Loading commit data... | |
p7626.C | Loading commit data... | |
p7635.C | Loading commit data... | |
p7651.C | Loading commit data... | |
p783.C | Loading commit data... | |
p783a.C | Loading commit data... | |
p783b.C | Loading commit data... | |
p784.C | Loading commit data... | |
p786.C | Loading commit data... | |
p7865.C | Loading commit data... | |
p7868.C | Loading commit data... | |
p789.C | Loading commit data... | |
p789a.C | Loading commit data... | |
p7912.C | Loading commit data... | |
p8009.C | Loading commit data... | |
p8018.C | Loading commit data... | |
p8039.C | Loading commit data... | |
p807.C | Loading commit data... | |
p807a.C | Loading commit data... | |
p811.C | Loading commit data... | |
p8154.C | Loading commit data... | |
p8155.C | Loading commit data... | |
p8175.C | Loading commit data... | |
p8269.C | Loading commit data... | |
p8460.C | Loading commit data... | |
p8483.C | Loading commit data... | |
p8620.C | Loading commit data... | |
p8786.C | Loading commit data... | |
p8804.C | Loading commit data... | |
p8825.C | Loading commit data... | |
p9068.C | Loading commit data... | |
p9129.C | Loading commit data... | |
p9206.C | Loading commit data... | |
p9506.C | Loading commit data... | |
p9706.C | Loading commit data... | |
p9732a.C | Loading commit data... | |
p9732b.C | Loading commit data... | |
p9732c.C | Loading commit data... | |
p991.C | Loading commit data... | |
parse1.C | Loading commit data... | |
pmd1.C | Loading commit data... | |
pmf1.C | Loading commit data... | |
pmf2.C | Loading commit data... | |
pmf3.C | Loading commit data... | |
pmf4.C | Loading commit data... | |
pmf6.C | Loading commit data... | |
pmf7.C | Loading commit data... | |
pmf8.C | Loading commit data... | |
pmf9.C | Loading commit data... | |
pt1.C | Loading commit data... | |
pt2.C | Loading commit data... | |
pt3.C | Loading commit data... | |
pt4.C | Loading commit data... | |
ref1.C | Loading commit data... | |
rtti1.C | Loading commit data... | |
rtti2.C | Loading commit data... | |
rtti3.C | Loading commit data... | |
s24939.C | Loading commit data... | |
s35520.C | Loading commit data... | |
s9959.C | Loading commit data... | |
scast1.C | Loading commit data... | |
sizeof.C | Loading commit data... | |
temp.C | Loading commit data... | |
thunk1.C | Loading commit data... | |
thunk2.C | Loading commit data... | |
thunk3.C | Loading commit data... | |
unroll1.C | Loading commit data... | |
unused.C | Loading commit data... | |
virt1.C | Loading commit data... | |
virt2.C | Loading commit data... | |
virt3.C | Loading commit data... | |
virt4.C | Loading commit data... | |
virt5.C | Loading commit data... | |
virt6.C | Loading commit data... | |
visibility-1.C | Loading commit data... | |
vtable1.C | Loading commit data... | |
warn1.C | Loading commit data... | |
warn2.C | Loading commit data... | |
warn3.C | Loading commit data... | |
warn4.C | Loading commit data... | |
warn5.C | Loading commit data... | |
warn6.C | Loading commit data... | |
warn7.C | Loading commit data... | |
warn8.C | Loading commit data... |